๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ“– Problem Solution/Programmers

[Swift] 2022 KAKAO BLIND RECRUITMENT ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ

by Fomagran ๐Ÿ’ป 2022. 1. 19.
728x90
๋ฐ˜์‘ํ˜•

 

Problem

 

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ

๋ฌธ์ œ ์„ค๋ช… ์‹ ์ž…์‚ฌ์› ๋ฌด์ง€๋Š” ๊ฒŒ์‹œํŒ ๋ถˆ๋Ÿ‰ ์ด์šฉ์ž๋ฅผ ์‹ ๊ณ ํ•˜๊ณ  ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋ฉ”์ผ๋กœ ๋ฐœ์†กํ•˜๋Š” ์‹œ์Šคํ…œ์„ ๊ฐœ๋ฐœํ•˜๋ ค ํ•ฉ๋‹ˆ๋‹ค. ๋ฌด์ง€๊ฐ€ ๊ฐœ๋ฐœํ•˜๋ ค๋Š” ์‹œ์Šคํ…œ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ ์œ ์ €๋Š” ํ•œ ๋ฒˆ์— ํ•œ ๋ช…์˜

programmers.co.kr


Solution

 

1. id_list๋ฅผ ์ธ๋ฑ์Šค์— ๋งž๊ฒŒ ๋”•์…”๋„ˆ๋ฆฌ์— ๋‹ด๋Š”๋‹ค.

 

    var idNumber:[String:Int] = [:]
    
    for (i,id) in id_list.enumerated() {
        idNumber[id] = i
    }

 

2. ์‹ ๊ณ  ๋‹นํ•œ ์‚ฌ๋žŒ์„ ํ‚ค๊ฐ’์œผ๋กœ,์‹ ๊ณ ํ•œ ์‚ฌ๋žŒ๋“ค์„ ๋ฐธ๋ฅ˜๊ฐ’์œผ๋กœ ๋”•์…”๋„ˆ๋ฆฌ์— ๋‹ด๋Š”๋‹ค.

 

   var reportInfo:[String:Set<String>] = [:]
 
   for r in report {
        let split = r.split(separator: " ")
        let report = String(split[0])
        let reported = String(split[1])
        if reportInfo[reported] == nil {
            reportInfo[reported] = [report]
        }else {
            reportInfo[reported]!.insert(report)
        }
    }

 

3. k๋ณด๋‹ค ๋” ๋งŽ์€ ์œ ์ €๋ฅผ ์‹ ๊ณ ํ•œ ์œ ์ €์˜ ์นด์šดํŠธ๋ฅผ ์„ธ์ค€๋‹ค,

    var reportCount:[Int] = Array(repeating: 0, count: id_list.count)

    for info in reportInfo {
            if info.value.count >= k {
                for id in info.value {
                    reportCount[idNumber[id]!] += 1
                }
            }
        }

 

4. reportCount๋ฅผ ๋ฐ˜ํ™˜ํ•ด์ค€๋‹ค.

 

    return reportCount

Source Code

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€