본문 바로가기

CodeSignal42

CodeSignal [42/60] bishopAndPawn Problem: Given the positions of a white bishop and a black pawn on the standard chess board, determine whether the bishop can capture the pawn in one move. The bishop has no restrictions in distance for each move, but is limited to diagonal movement. Check out the example below to see how it can move: Example For bishop = "a1" and pawn = "c3", the output should be bishopAndPawn(bishop, pawn) = t.. 2020. 5. 26.
CodeSignal [41/60] digitDegree Problem: Let's define digit degree of some positive integer as the number of times we need to replace this number with the sum of its digits until we get to a one digit number. Given an integer, find its digit degree. Example For n = 5, the output should be digitDegree(n) = 0; For n = 100, the output should be digitDegree(n) = 1. 1 + 0 + 0 = 1. For n = 91, the output should be digitDegree(n) = 2.. 2020. 5. 26.
CodeSignal [40/60] longestDigitsPrefix Problem: Given a string, output its longest prefix which contains only digits. Example For inputString = "123aa1", the output should be longestDigitsPrefix(inputString) = "123". -Summary- 1. inputString의 각 캐릭터들을 앞에서부터 차례차례 비교하여 만약에 digit일 경우에는 longestDigits 에 넣어주고 아닐경우에는 바로 break 하여 loop 을 나옴 2. loop을 돌며 저장해온 longestDigits 값 return. 모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFigh.. 2020. 5. 26.
CodeSignal [39/60] knapsackLight Problem: You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the second item weighs weight2 and is worth value2. What is the total maximum value of the items you can take with you, assuming that your max weight capacity is maxW and you can't come back for the items later? Note that there are only two items and you can't bring more than one item of each.. 2020. 5. 26.
CodeSignal [38/60] growingPlant Problem: Caring for a plant can be hard work, but since you tend to it regularly, you have a plant that grows consistently. Each day, its height increases by a fixed amount represented by the integer upSpeed. But due to lack of sunlight, the plant decreases in height every night, by an amount represented by downSpeed. Since you grew the plant from a seed, it started at height 0 initially. Given .. 2020. 5. 25.
CodeSignal [37/60] arrayMaxConsecutiveSum Problem: Given array of integers, find the maximal possible sum of some of its k consecutive elements. Example For inputArray = [2, 3, 5, 1, 6] and k = 2, the output should be arrayMaxConsecutiveSum(inputArray, k) = 8. All possible sums of 2 consecutive elements are: 2 + 3 = 5; 3 + 5 = 8; 5 + 1 = 6; 1 + 6 = 7. Thus, the answer is 8. -Summary- 1. Set the max_sum as first k consecutive sum from th.. 2020. 5. 25.