๊ด€๋ฆฌ ๋ฉ”๋‰ด

๐Ÿ–ฅ dev-ruby

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][Lv.2] ์ˆœ์œ„ ๊ฒ€์ƒ‰ | ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ | 2021 KAKAO BLIND RECRUITMENT ๋ณธ๋ฌธ

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][Lv.2] ์ˆœ์œ„ ๊ฒ€์ƒ‰ | ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ | 2021 KAKAO BLIND RECRUITMENT

ruby_s 2021. 12. 31. 20:59
728x90
๋ฐ˜์‘ํ˜•
SMALL

๋ฌธ์ œ ์„ค๋ช…

[๋ณธ ๋ฌธ์ œ๋Š” ์ •ํ™•์„ฑ๊ณผ ํšจ์œจ์„ฑ ํ…Œ์ŠคํŠธ ๊ฐ๊ฐ ์ ์ˆ˜๊ฐ€ ์žˆ๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.]

์นด์นด์˜ค๋Š” ํ•˜๋ฐ˜๊ธฐ ๊ฒฝ๋ ฅ ๊ฐœ๋ฐœ์ž ๊ณต๊ฐœ์ฑ„์šฉ์„ ์ง„ํ–‰ ์ค‘์— ์žˆ์œผ๋ฉฐ ํ˜„์žฌ ์ง€์›์„œ ์ ‘์ˆ˜์™€ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ๊ฐ€ ์ข…๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฒˆ ์ฑ„์šฉ์—์„œ ์ง€์›์ž๋Š” ์ง€์›์„œ ์ž‘์„ฑ ์‹œ ์•„๋ž˜์™€ ๊ฐ™์ด 4๊ฐ€์ง€ ํ•ญ๋ชฉ์„ ๋ฐ˜๋“œ์‹œ ์„ ํƒํ•˜๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

  • ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ฐธ์—ฌ ๊ฐœ๋ฐœ์–ธ์–ด ํ•ญ๋ชฉ์— cpp, java, python ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ์ง€์› ์ง๊ตฐ ํ•ญ๋ชฉ์— backend์™€ frontend ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ์ง€์› ๊ฒฝ๋ ฅ๊ตฌ๋ถ„ ํ•ญ๋ชฉ์— junior์™€ senior ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ์„ ํ˜ธํ•˜๋Š” ์†Œ์šธํ‘ธ๋“œ๋กœ chicken๊ณผ pizza ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ธ์žฌ์˜์ž…ํŒ€์— ๊ทผ๋ฌดํ•˜๊ณ  ์žˆ๋Š” ๋‹ˆ๋‹ˆ์ฆˆ๋Š” ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ์ฑ„์šฉ์— ์ฐธ์—ฌํ•œ ๊ฐœ๋ฐœํŒ€๋“ค์— ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด ์ง€์›์ž๋“ค์˜ ์ง€์› ์กฐ๊ฑด์„ ์„ ํƒํ•˜๋ฉด ํ•ด๋‹น ์กฐ๊ฑด์— ๋งž๋Š” ์ง€์›์ž๊ฐ€ ๋ช‡ ๋ช…์ธ ์ง€ ์‰ฝ๊ฒŒ ์•Œ ์ˆ˜ ์žˆ๋Š” ๋„๊ตฌ๋ฅผ ๋งŒ๋“ค๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, ๊ฐœ๋ฐœํŒ€์—์„œ ๊ถ๊ธˆํ•ดํ•˜๋Š” ๋ฌธ์˜์‚ฌํ•ญ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ˜•ํƒœ๊ฐ€ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ฝ”๋”ฉํ…Œ์ŠคํŠธ์— java๋กœ ์ฐธ์—ฌํ–ˆ์œผ๋ฉฐ, backend ์ง๊ตฐ์„ ์„ ํƒํ–ˆ๊ณ , junior ๊ฒฝ๋ ฅ์ด๋ฉด์„œ, ์†Œ์šธํ‘ธ๋“œ๋กœ pizza๋ฅผ ์„ ํƒํ•œ ์‚ฌ๋žŒ ์ค‘ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 50์  ์ด์ƒ ๋ฐ›์€ ์ง€์›์ž๋Š” ๋ช‡ ๋ช…์ธ๊ฐ€?

๋ฌผ๋ก  ์ด ์™ธ์—๋„ ๊ฐ ๊ฐœ๋ฐœํŒ€์˜ ์ƒํ™ฉ์— ๋”ฐ๋ผ ์•„๋ž˜์™€ ๊ฐ™์ด ๋‹ค์–‘ํ•œ ํ˜•ํƒœ์˜ ๋ฌธ์˜๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์ฝ”๋”ฉํ…Œ์ŠคํŠธ์— python์œผ๋กœ ์ฐธ์—ฌํ–ˆ์œผ๋ฉฐ, frontend ์ง๊ตฐ์„ ์„ ํƒํ–ˆ๊ณ , senior ๊ฒฝ๋ ฅ์ด๋ฉด์„œ, ์†Œ์šธํ‘ธ๋“œ๋กœ chicken์„ ์„ ํƒํ•œ ์‚ฌ๋žŒ ์ค‘ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 100์  ์ด์ƒ ๋ฐ›์€ ์‚ฌ๋žŒ์€ ๋ชจ๋‘ ๋ช‡ ๋ช…์ธ๊ฐ€?
  • ์ฝ”๋”ฉํ…Œ์ŠคํŠธ์— cpp๋กœ ์ฐธ์—ฌํ–ˆ์œผ๋ฉฐ, senior ๊ฒฝ๋ ฅ์ด๋ฉด์„œ, ์†Œ์šธํ‘ธ๋“œ๋กœ pizza๋ฅผ ์„ ํƒํ•œ ์‚ฌ๋žŒ ์ค‘ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 100์  ์ด์ƒ ๋ฐ›์€ ์‚ฌ๋žŒ์€ ๋ชจ๋‘ ๋ช‡ ๋ช…์ธ๊ฐ€?
  • backend ์ง๊ตฐ์„ ์„ ํƒํ–ˆ๊ณ , senior ๊ฒฝ๋ ฅ์ด๋ฉด์„œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 200์  ์ด์ƒ ๋ฐ›์€ ์‚ฌ๋žŒ์€ ๋ชจ๋‘ ๋ช‡ ๋ช…์ธ๊ฐ€?
  • ์†Œ์šธํ‘ธ๋“œ๋กœ chicken์„ ์„ ํƒํ•œ ์‚ฌ๋žŒ ์ค‘ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 250์  ์ด์ƒ ๋ฐ›์€ ์‚ฌ๋žŒ์€ ๋ชจ๋‘ ๋ช‡ ๋ช…์ธ๊ฐ€?
  • ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 150์  ์ด์ƒ ๋ฐ›์€ ์‚ฌ๋žŒ์€ ๋ชจ๋‘ ๋ช‡ ๋ช…์ธ๊ฐ€?

์ฆ‰, ๊ฐœ๋ฐœํŒ€์—์„œ ๊ถ๊ธˆํ•ดํ•˜๋Š” ๋‚ด์šฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ˜•ํƒœ๋ฅผ ๊ฐ–์Šต๋‹ˆ๋‹ค.

* [์กฐ๊ฑด]์„ ๋งŒ์กฑํ•˜๋Š” ์‚ฌ๋žŒ ์ค‘ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ X์  ์ด์ƒ ๋ฐ›์€ ์‚ฌ๋žŒ์€ ๋ชจ๋‘ ๋ช‡ ๋ช…์ธ๊ฐ€?

[๋ฌธ์ œ]

์ง€์›์ž๊ฐ€ ์ง€์›์„œ์— ์ž…๋ ฅํ•œ 4๊ฐ€์ง€์˜ ์ •๋ณด์™€ ํš๋“ํ•œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ๊ตฌ์„ฑํ•œ ๊ฐ’์˜ ๋ฐฐ์—ด info, ๊ฐœ๋ฐœํŒ€์ด ๊ถ๊ธˆํ•ดํ•˜๋Š” ๋ฌธ์˜์กฐ๊ฑด์ด ๋ฌธ์ž์—ด ํ˜•ํƒœ๋กœ ๋‹ด๊ธด ๋ฐฐ์—ด query๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ,
๊ฐ ๋ฌธ์˜์กฐ๊ฑด์— ํ•ด๋‹นํ•˜๋Š” ์‚ฌ๋žŒ๋“ค์˜ ์ˆซ์ž๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋ฐฐ์—ด์— ๋‹ด์•„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด ์ฃผ์„ธ์š”.

[์ œํ•œ์‚ฌํ•ญ]

  • info ๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋Š” 1 ์ด์ƒ 50,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค.
  • info ๋ฐฐ์—ด ๊ฐ ์›์†Œ์˜ ๊ฐ’์€ ์ง€์›์ž๊ฐ€ ์ง€์›์„œ์— ์ž…๋ ฅํ•œ 4๊ฐ€์ง€ ๊ฐ’๊ณผ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ ํ•ฉ์นœ "๊ฐœ๋ฐœ์–ธ์–ด ์ง๊ตฐ ๊ฒฝ๋ ฅ ์†Œ์šธํ‘ธ๋“œ ์ ์ˆ˜" ํ˜•์‹์ž…๋‹ˆ๋‹ค.
    • ๊ฐœ๋ฐœ์–ธ์–ด๋Š” cpp, java, python ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
    • ์ง๊ตฐ์€ backend, frontend ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
    • ๊ฒฝ๋ ฅ์€ junior, senior ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
    • ์†Œ์šธํ‘ธ๋“œ๋Š” chicken, pizza ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
    • ์ ์ˆ˜๋Š” ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ ์˜๋ฏธํ•˜๋ฉฐ, 1 ์ด์ƒ 100,000 ์ดํ•˜์ธ ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค.
    • ๊ฐ ๋‹จ์–ด๋Š” ๊ณต๋ฐฑ๋ฌธ์ž(์ŠคํŽ˜์ด์Šค ๋ฐ”) ํ•˜๋‚˜๋กœ ๊ตฌ๋ถ„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • query ๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋Š” 1 ์ด์ƒ 100,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค.
  • query์˜ ๊ฐ ๋ฌธ์ž์—ด์€ "[์กฐ๊ฑด] X" ํ˜•์‹์ž…๋‹ˆ๋‹ค.
    • [์กฐ๊ฑด]์€ "๊ฐœ๋ฐœ์–ธ์–ด and ์ง๊ตฐ and ๊ฒฝ๋ ฅ and ์†Œ์šธํ‘ธ๋“œ" ํ˜•์‹์˜ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.
    • ์–ธ์–ด๋Š” cpp, java, python, - ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
    • ์ง๊ตฐ์€ backend, frontend, - ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
    • ๊ฒฝ๋ ฅ์€ junior, senior, - ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
    • ์†Œ์šธํ‘ธ๋“œ๋Š” chicken, pizza, - ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.
    • '-' ํ‘œ์‹œ๋Š” ํ•ด๋‹น ์กฐ๊ฑด์„ ๊ณ ๋ คํ•˜์ง€ ์•Š๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.
    • X๋Š” ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ ์˜๋ฏธํ•˜๋ฉฐ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ์‚ฌ๋žŒ ์ค‘ X์  ์ด์ƒ ๋ฐ›์€ ์‚ฌ๋žŒ์€ ๋ชจ๋‘ ๋ช‡ ๋ช…์ธ ์ง€๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.
    • ๊ฐ ๋‹จ์–ด๋Š” ๊ณต๋ฐฑ๋ฌธ์ž(์ŠคํŽ˜์ด์Šค ๋ฐ”) ํ•˜๋‚˜๋กœ ๊ตฌ๋ถ„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
    • ์˜ˆ๋ฅผ ๋“ค๋ฉด, "cpp and - and senior and pizza 500"์€ "cpp๋กœ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ๋ฅผ ๋ดค์œผ๋ฉฐ, ๊ฒฝ๋ ฅ์€ senior ์ด๋ฉด์„œ ์†Œ์šธํ‘ธ๋“œ๋กœ pizza๋ฅผ ์„ ํƒํ•œ ์ง€์›์ž ์ค‘ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 500์  ์ด์ƒ ๋ฐ›์€ ์‚ฌ๋žŒ์€ ๋ชจ๋‘ ๋ช‡ ๋ช…์ธ๊ฐ€?"๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

[์ž…์ถœ๋ ฅ ์˜ˆ]
info query result
["java backend junior pizza 150","python frontend senior chicken 210","python frontend senior chicken 150","cpp backend senior pizza 260","java backend junior chicken 80","python backend senior chicken 50"] ["java and backend and junior and pizza 100","python and frontend and senior and chicken 200","cpp and - and senior and pizza 250","- and backend and senior and - 150","- and - and - and chicken 100","- and - and - and - 150"] [1,1,1,1,2,4]
์ž…์ถœ๋ ฅ ์˜ˆ์— ๋Œ€ํ•œ ์„ค๋ช…

์ง€์›์ž ์ •๋ณด๋ฅผ ํ‘œ๋กœ ๋‚˜ํƒ€๋‚ด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์–ธ์–ด ์ง๊ตฐ ๊ฒฝ๋ ฅ ์†Œ์šธ ํ‘ธ๋“œ ์ ์ˆ˜
java backend junior pizza 150
python frontend senior chicken 210
python frontend senior chicken 150
cpp backend senior pizza 260
java backend junior chicken 80
python backend senior chicken 50
  • "java and backend and junior and pizza 100" : java๋กœ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ๋ฅผ ๋ดค์œผ๋ฉฐ, backend ์ง๊ตฐ์„ ์„ ํƒํ–ˆ๊ณ  junior ๊ฒฝ๋ ฅ์ด๋ฉด์„œ ์†Œ์šธํ‘ธ๋“œ๋กœ pizza๋ฅผ ์„ ํƒํ•œ ์ง€์›์ž ์ค‘ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 100์  ์ด์ƒ ๋ฐ›์€ ์ง€์›์ž๋Š” 1๋ช… ์ž…๋‹ˆ๋‹ค.
  • "python and frontend and senior and chicken 200" : python์œผ๋กœ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ๋ฅผ ๋ดค์œผ๋ฉฐ, frontend ์ง๊ตฐ์„ ์„ ํƒํ–ˆ๊ณ , senior ๊ฒฝ๋ ฅ์ด๋ฉด์„œ ์†Œ์šธ ํ‘ธ๋“œ๋กœ chicken์„ ์„ ํƒํ•œ ์ง€์›์ž ์ค‘ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 200์  ์ด์ƒ ๋ฐ›์€ ์ง€์›์ž๋Š” 1๋ช… ์ž…๋‹ˆ๋‹ค.
  • "cpp and - and senior and pizza 250" : cpp๋กœ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ๋ฅผ ๋ดค์œผ๋ฉฐ, senior ๊ฒฝ๋ ฅ์ด๋ฉด์„œ ์†Œ์šธํ‘ธ๋“œ๋กœ pizza๋ฅผ ์„ ํƒํ•œ ์ง€์›์ž ์ค‘ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 250์  ์ด์ƒ ๋ฐ›์€ ์ง€์›์ž๋Š” 1๋ช… ์ž…๋‹ˆ๋‹ค.
  • "- and backend and senior and - 150" : backend ์ง๊ตฐ์„ ์„ ํƒํ–ˆ๊ณ , senior ๊ฒฝ๋ ฅ์ธ ์ง€์›์ž ์ค‘ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 150์  ์ด์ƒ ๋ฐ›์€ ์ง€์›์ž๋Š” 1๋ช… ์ž…๋‹ˆ๋‹ค.
  • "- and - and - and chicken 100" : ์†Œ์šธํ‘ธ๋“œ๋กœ chicken์„ ์„ ํƒํ•œ ์ง€์›์ž ์ค‘ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 100์  ์ด์ƒ์„ ๋ฐ›์€ ์ง€์›์ž๋Š” 2๋ช… ์ž…๋‹ˆ๋‹ค.
  • "- and - and - and - 150" : ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ ์ˆ˜๋ฅผ 150์  ์ด์ƒ ๋ฐ›์€ ์ง€์›์ž๋Š” 4๋ช… ์ž…๋‹ˆ๋‹ค.

 

๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด

 

์ด ๋ฌธ์ œ๋Š” ์ด๋ถ„ ํƒ์ƒ‰์œผ๋กœ ํ’€์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ๊ฐ™๋‹ค.

์ฒ˜์Œ์— ํ‘ผ ํ’€์ด (์ •ํ™•์„ฑ success, ํšจ์œจ์„ฑ fail)

function solution(info, query) {    // ์ •ํ™•์„ฑ success, ํšจ์œจ์„ฑ fail
    const infoSplited = info.map((str)=>str.split(' '));
    const querySplited = query.map((str)=>str.split(/ and | /g));
    let result = new Array(query.length).fill(0);
    querySplited.forEach((arr, idx)=>{
        infoSplited.forEach((i)=>{
            const copyQuery = arr.slice(0, -1).filter((v)=>v!=='-');
            let intersection = copyQuery.filter(x=>i.includes(x)).length;
            intersection === copyQuery.length && Number(i[i.length-1]) >= Number(arr[arr.length-1]) ? result[idx] += 1 : null;
        })
    })
    return result;
}
728x90
๋ฐ˜์‘ํ˜•
LIST