본문 바로가기

전체 글55

[HACKERRANK] - Recursive Digit Sum www.hackerrank.com/challenges/recursive-digit-sum/problem Recursive Digit Sum | HackerRank recursively sum all digits in a number until there is only one left www.hackerrank.com INPUT : n, k 수 n을 k번 나열했을 때, 각 자리의 합을 재귀적으로 구해 한 자리 수의 답을 출력하는 문제 k의 영향을 받는 최초의 결과는 n의 각 자리 숫자의 합의 k배 이후 res가 10보다 작아질 때 까지 반복 def superDigit(n, k): res = sum(list(map(int,str(n))))*k while res>=10: res = sum(list(map(in.. 2021. 2. 4.
[HACKERRANK] - Crossword Puzzle www.hackerrank.com/challenges/crossword-puzzle/problem Crossword Puzzle | HackerRank Given a Crossword Grid, and a set of words, fill up the crossword. www.hackerrank.com '-' 칸을 words로 주어진 단어들로 채우는 문제 우선 채울 수 있는 칸을 먼저 찾은 후에, 해당 칸을 Recursive하게 채운다. word의 수가 최대 10개로 제한되어있기 때문에 해당 칸에 들어갈 수 있는 단어를 모두 확인하고 대입해본다. deepcopy() 함수를 사용해 완전히 새로운 배열 생성 from collections import deque import copy answer = None.. 2021. 2. 4.
[HACKERRANK] - Recursion: Davis' Staircase www.hackerrank.com/challenges/ctci-recursive-staircase/problem Recursion: Davis' Staircase | HackerRank Find the number of ways to get from the bottom of a staircase to the top if you can jump 1, 2, or 3 stairs at a time. www.hackerrank.com 한 번에 1, 2, 3칸씩 계단을 오를 수 있을 때, 계단을 오르는 모든 경우의 수의 개수를 구하는 문제. 계단 수 n, 경우의 수 f(n) f(1) = [1] f(2) = [11, 2] f(3) = [111, 12, 21, 3] 계단이 4개 이상일 때 부터는 오를 수 있는 칸 수.. 2021. 2. 3.