[후기] 2020년 하반기 SW개발 신입 LINER 공개채용 온라인 코딩테스트

Jake_Young·2020년 9월 13일
5
post-thumbnail

🥶 총평

  • 문제 난이도가 어렵지는 않았다.
  • 다만 시뮬레이션이 많아 읽고 푸는데 많은 시간이 소요되었다.
  • 총 6문제를 3시간 안에 풀어야했던 만큼 시간 압박이 심했다.
  • 테스트 케이스 기준 6 문제 중 5문제를 풀었다.
  • 마지막 문제는 블랙잭 규칙에 관한 것이었는데, 예외와 요구 사항이 많아 시간이 부족했다.

⭐ 부정행위 관련 안내

  • 역시나 내 코드를 올리는 것은 상관이 없을 것 같아 아래 올린다


🤞 후기 인증용 정답

1번 문제 풀이

def solution(boxes):
    count = 0
    data = set()
    for box in boxes:
        a, b = box
        if a in data:
            count += 1
            data.remove(a)
        else:
            data.add(a)
        if b in data:
            count += 1
            data.remove(b)
        else:
            data.add(b)
    return len(boxes) - count

2번 문제 풀이

def solution(ball, order):
    answer = []
    queue = [-1, -1]
    for number in order:
        if ball[0] == number:
            answer.append(ball.pop(0))

            while ball:
                for index in range(-1, -len(queue) + 1, -1):
                    if queue[index] == ball[0]:
                        answer.append(ball.pop(0))
                        queue.pop(index)
                        break
                else:
                    break

        elif ball[-1] == number:
            answer.append(ball.pop(-1))

            while ball:
                for index in range(-1, -len(queue) + 1, -1):
                    if queue[index] == ball[-1]:
                        answer.append(ball.pop(-1))
                        queue.pop(index)
                        break
                else:
                    break

        else:
            queue.insert(2, number)

    return answer

3번 문제 풀이

answer_count = float('inf')
answer_number = -1


def bfs(current, count):
    global answer_count, answer_number
    if len(current) > 2:
        length = len(current)
        mid = length // 2
        if length % 2:
            # 홀수니까 양쪽으로 쪼개야 함. 0인 경우에는 양쪽 탐색

            if current[mid] != "0":
                bfs(str(int(current[:mid]) + int(current[mid:])), count+1)
            else:
                for index in range(mid+1, len(current)):
                    if current[index] != "0":
                        bfs(str(int(current[:index]) + int(current[index:])), count + 1)
                else:
                    bfs(current[:-1], count + 1)

            mid += 1
            if current[mid] != "0":
                bfs(str(int(current[:mid]) + int(current[mid:])), count+1)
            else:
                for index in range(mid+1, len(current)):
                    if current[index] != "0":
                        bfs(str(int(current[:index]) + int(current[index:])), count + 1)
                else:
                    bfs(current[:-1], count + 1)

        else:
            # 짝수니까 정 중앙에서 쪼개야 함. 0인 경우에는 양쪽 탐색
            if current[mid] != "0":
                bfs(str(int(current[:mid]) + int(current[mid:])), count+1)
            else:
                for index in range(mid+1, len(current)):
                    if current[index] != "0":
                        bfs(str(int(current[:index]) + int(current[index:])), count + 1)
                else:
                    bfs(current[:-1], count + 1)

    elif len(current) == 2:
        bfs(str(int(current[0]) + int(current[1])), count + 1)
    else:
        if count < answer_count:
            answer_count = count
            answer_number = current


def solution(n):
    global answer_count, answer_number
    string_number = str(n)
    bfs(string_number, 0)
    return [answer_count, int(answer_number)]

4번 문제 풀이

rotation = {
    "up": ["left", "up", "right", "down"],
    "left": ["down", "left", "up", "right"],
    "down": ["right", "down", "left", "up"],
    "right": ["up", "right", "down", "left"]
}

direction = {
    "up": [0, -1],
    "left": [-1, 0],
    "down": [0, 1],
    "right": [1, 0]
}


def solution(maze):
    global rotation, direction
    size = len(maze)
    answer = 0
    coord = [0, 0, "right"]
    while True:
        x, y, arrow = coord
        for rot in rotation[arrow]:
            dx, dy = direction[rot]
            new_x, new_y = x + dx, y + dy
            if 0 <= new_x < size and 0 <= new_y < size and not maze[new_y][new_x]:
                coord = [new_x, new_y, rot]
                answer += 1
                break
        if coord[0] == size - 1 and coord[1] == size - 1:
            break
    return answer

5번 문제 풀이: 못 풀어서 안 올림

6번 문제 풀이:

def solution(companies, applicants):

    answer = []

    company_state = {}
    applicant_status = []

    data_companies = {}
    for company in companies:
        name, hope, count = company.split()
        data_companies[name] = [list(hope), int(count)]
        company_state[name] = []

    data_applicants = {}
    for applicant in applicants:
        name, hope, count = applicant.split()
        data_applicants[name] = list(hope[:int(count)])
        applicant_status.append(name)

    while applicant_status:

        # 지원자 1순위 기업에 지원하기
        for applicant in applicant_status:
            if data_applicants.get(applicant):
                hope = data_applicants[applicant].pop(0)
                if not data_applicants[applicant]:
                    del data_applicants[applicant]
                company_state[hope].append(applicant)

        applicant_status = []

        # 기업이 우선 순위에 맞춰 짜르기
        for company in company_state:
            if len(company_state[company]) > data_companies[company][1]:
                # 우선순위에 맞춰 자르자
                limit = data_companies[company][1]
                failed_list = set(company_state[company])
                passed_list = set()
                for hope in data_companies[company][0]:
                    if hope in failed_list:
                        passed_list.add(hope)
                        limit -= 1
                        if limit == 0:
                            break
                for passed in passed_list:
                    failed_list.remove(passed)
                company_state[company] = list(passed_list)
                applicant_status += list(failed_list)

        # 잔여자 외는 전부 지우기
        new_applicant_status = []
        for applicant in applicant_status:
            new_applicant_status.append(applicant)
        applicant_status = new_applicant_status

    for company in company_state:
        passed = "".join(sorted(company_state[company]))
        answer.append(company+"_"+passed)

    return answer
profile
자바스크립트와 파이썬 그리고 컴퓨터와 네트워크

2개의 댓글

comment-user-thumbnail
2020년 11월 2일

안녕하세요. 프로그래머스팀 입니다.

귀하가 작성한 글을 내려주시기 바랍니다.

프로그래머스는 코딩테스트 문제에 대한 저작권 침해 행위를 심각하게 인식하고 있습니다.
저작권이 있는 콘텐츠 및 2차 저작물을 공개하여 본인의 영리를 취하는 행위는 민사적 책임은 물론 형사적으로도 처벌 대상이 될 수 있습니다.
문제를 유출하는 행위 또는 이를 활용한 2차 저작물을 제작해 공개하는 권리침해를 삼가 주시기를 요청드리며, 이 글을 비공개 처리/삭제해주세요.

감사합니다.
프로그래머스 팀 드림.

답글 달기
comment-user-thumbnail
2020년 12월 10일

greatpeople, 2020년 11월 2일
안녕하세요. 프로그래머스팀 입니다.

귀하가 작성한 글을 내려주시기 바랍니다.

프로그래머스는 코딩테스트 문제에 대한 저작권 침해 행위를 심각하게 인식하고 있습니다.
저작권이 있는 콘텐츠 및 2차 저작물을 공개하여 본인의 영리를 취하는 행위는 민사적 책임은 물론 형사적으로도 처벌 대상이 될 수 있습니다.
문제를 유출하는 행위 또는 이를 활용한 2차 저작물을 제작해 공개하는 권리침해를 삼가 주시기를 요청드리며, 이 글을 비공개 처리/삭제해주세요.

감사합니다.
프로그래머스 팀 드림.


저는 프로그래머스 팀의 콘텐츠 및 2차 저작물(원래 있던 저작물을 번역, 편곡, 각색하거나 영상으로 제작하는 등의 방법으로 새롭게 재창작한 저작물을 말합니다-한국저작권위원회)을 공개한 적이 없습니다. 따라서 저작권을 침해하였다는 프로그래머스팀의 댓글이 이해가 되지 않습니다. 위 글의 어느 부분이 문제가 된다는 것인지 정확히 지적해주신다면 그에 맞게 조치해드리도록 하겠습니다.

답글 달기