240424

1

๋ฌธ์ œ : K๋ฒˆ์งธ์ˆ˜ ๋‚œ์ด๋„ : Lv.1 ์„ค๋ช… :

๋ฐฐ์—ด array์˜ i๋ฒˆ์งธ ์ˆซ์ž๋ถ€ํ„ฐ j๋ฒˆ์งธ ์ˆซ์ž๊นŒ์ง€ ์ž๋ฅด๊ณ  ์ •๋ ฌํ–ˆ์„ ๋•Œ, k๋ฒˆ์งธ์— ์žˆ๋Š” ์ˆ˜๋ฅผ ๊ตฌํ•˜๋ ค ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด array๊ฐ€ [1, 5, 2, 6, 3, 7, 4], i = 2, j = 5, k = 3์ด๋ผ๋ฉด

array์˜ 2๋ฒˆ์งธ๋ถ€ํ„ฐ 5๋ฒˆ์งธ๊นŒ์ง€ ์ž๋ฅด๋ฉด [5, 2, 6, 3]์ž…๋‹ˆ๋‹ค. 1์—์„œ ๋‚˜์˜จ ๋ฐฐ์—ด์„ ์ •๋ ฌํ•˜๋ฉด [2, 3, 5, 6]์ž…๋‹ˆ๋‹ค. 2์—์„œ ๋‚˜์˜จ ๋ฐฐ์—ด์˜ 3๋ฒˆ์งธ ์ˆซ์ž๋Š” 5์ž…๋‹ˆ๋‹ค. ๋ฐฐ์—ด array, [i, j, k]๋ฅผ ์›์†Œ๋กœ ๊ฐ€์ง„ 2์ฐจ์› ๋ฐฐ์—ด commands๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, commands์˜ ๋ชจ๋“  ์›์†Œ์— ๋Œ€ํ•ด ์•ž์„œ ์„ค๋ช…ํ•œ ์—ฐ์‚ฐ์„ ์ ์šฉํ–ˆ์„ ๋•Œ ๋‚˜์˜จ ๊ฒฐ๊ณผ๋ฅผ ๋ฐฐ์—ด์— ๋‹ด์•„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.

array์˜ ๊ธธ์ด๋Š” 1 ์ด์ƒ 100 ์ดํ•˜์ž…๋‹ˆ๋‹ค. array์˜ ๊ฐ ์›์†Œ๋Š” 1 ์ด์ƒ 100 ์ดํ•˜์ž…๋‹ˆ๋‹ค. commands์˜ ๊ธธ์ด๋Š” 1 ์ด์ƒ 50 ์ดํ•˜์ž…๋‹ˆ๋‹ค. commands์˜ ๊ฐ ์›์†Œ๋Š” ๊ธธ์ด๊ฐ€ 3์ž…๋‹ˆ๋‹ค.

ํ’€์ด-1

function solution(array, commands) {
    var answer = [];

    commands.map((command) => {
        let result = array.slice(command[0] -1, command[1]).sort((a, b) => a - b)
        answer.push(result[command[2]-1])
    })
    return answer;
}

2

๋ฌธ์ œ : ์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜? ๋‚œ์ด๋„ : Lv.1 ์„ค๋ช… :

๊ธธ์ด๊ฐ€ n์ด๊ณ , "์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜...."์™€ ๊ฐ™์€ ํŒจํ„ด์„ ์œ ์ง€ํ•˜๋Š” ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•˜์„ธ์š”. ์˜ˆ๋ฅผ๋“ค์–ด n์ด 4์ด๋ฉด "์ˆ˜๋ฐ•์ˆ˜๋ฐ•"์„ ๋ฆฌํ„ดํ•˜๊ณ  3์ด๋ผ๋ฉด "์ˆ˜๋ฐ•์ˆ˜"๋ฅผ ๋ฆฌํ„ดํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

ํ’€์ด

function solution(n) {
    let answer = Array(n).fill("1")

    answer.map((num, i) => {
        if((i+1) % 2 === 0) {
            answer[i] = "๋ฐ•"
        } else {
            answer[i] = "์ˆ˜"
        }
    })
    return answer.join('')
}

Last updated