[코딩테스트] 네이버웹툰 개발 챌린지(프로그래머스)

suram·2021년 7월 4일
5

네이버웹툰 개발 챌린지

  • 일시 : 2021년 7월 4일
  • 플랫폼 : 프로그래머스
  • 총 문제 : 3문제
  • 응시 언어 : python

연습용으로 보았고, AI application engineer 직군을 지원했다. 이후에 과제 테스트도 있다.

문제 1 번

solved

  • 분류 : 반복문, 배열

lottery = [[1,0],[35,0],[1,0],[100,1],[35,1],[100,1],[35,0],[1,1],[1,1]]

def solution(lottery):
    record = {}
    for user in lottery:
        if record.get(user[0]) is None:
            record[user[0]] = [1, user[1]]
            continue
        value = record.get(user[0])
        if value[1] == 0 :
            value[0] += 1
            value[1] = user[1]
            record[user[0]] = value
    answer = [0,0]

    for user, result in record.items():
        if result[1] :
            answer[0] += result[0]
            answer[1] += 1
    return answer[0]//answer[1] if answer[1] > 0 else 0


print(solution(lottery))

문제 2번

solved

  • 분류 : BFS
from collections import deque
import math
row, col = (len(grid), len(grid[0]))
path = [[math.inf]*col for _ in range(row)]
que = deque([(0,0,0)])
dx = [0,1]
dy = [1,0]

while que:
    node = que.popleft()
    x , y = node[:2]
    path[x][y] = min(path[x][y], grid[x][y] + node[-1])

    for i in range(2):
        nx = x + dx[i]
        ny = y + dy[i]

        if 0 <= nx < row and 0 <= ny < col :
            que.append((nx,ny,path[x][y]))
            
print(path[row-1][col-1])

문제 3번

  • 분류 : DFS
    unsolved 시험 끝나고 나서 마저 풀었다.ㅠ
from copy import  deepcopy
import math

arr = [5,4,3,2,1]
k = 4
limit = len(arr)
pos = [-1] * (len(arr)+1)
for i in range(len(arr)):
    pos[arr[i]] = i

cnt = 0
answer = math.inf

def DFS(max, arr , cnt,ordered):

    if ordered == limit:
        global answer
        answer = min(answer, cnt)
        return

    if max == arr.index(max)+1:
        DFS(max-1, arr, cnt,ordered+1)
        return

    for i in range(1, k+1):

        index = arr.index(max)

        if index+i < limit - ordered:
            new_arr = deepcopy(arr)
            new_arr[index], new_arr[index + i] = new_arr[index + i], new_arr[index]
            DFS(max, new_arr, cnt + 1, ordered)


DFS(max(arr), arr, 0, 0)
print(answer)

결론: 구현, DFS 문제를 더 풀어보자.

profile
녁므

4개의 댓글

comment-user-thumbnail
2021년 7월 6일

저는 2번문제 dp로 풀었는데 잘 푼지 몰겠네요...

2개의 답글