본문 바로가기
300x250

전체 글241

Codesignal - commonCharacterCount Given two strings, find the number of common characters between them. Example For s1 = "aabcc" and s2 = "adcaa", the output should be commonCharacterCount(s1, s2) = 3. Strings have 3 common characters - 2 "a"s and 1 "c". 설명 s1과 s2의 문자열을 분석하여 똑같은 문자의 개수를 구한다. 풀이 s1의 "aabcc"에 a가 2개, s2의 "adcaa"에도 a가 3개 => count에 2 s1의 "aabcc"에 c가 2개, s2의 "adcaa"에 c가 한개 => count에 1 총합 2+1 3을 리턴한다. func commonCharac.. 2021. 5. 1.
Codesignal - Circle of Numbers Consider integer numbers from 0 to n - 1 written down along the circle in such a way that the distance between any two neighboring numbers is equal (note that 0 and n - 1 are neighboring, too). Given n and firstNumber, find the number which is written in the radially opposite position to firstNumber. Example For n = 10 and firstNumber = 2, the output should be circleOfNumbers(n, firstNumber) = 7.. 2021. 5. 1.
Codesignal - chessBoardCellColor Given two cells on the standard chess board, determine whether they have the same color or not. Example For cell1 = "A1" and cell2 = "C3", the output should be chessBoardCellColor(cell1, cell2) = true. For cell1 = "A1" and cell2 = "H3", the output should be chessBoardCellColor(cell1, cell2) = false. Input/Output [execution time limit] 20 seconds (swift) [input] string cell1 Guaranteed constraint.. 2021. 5. 1.
Codesignal - checkPalindrome Given the string, check if it is a palindrome. Example. For inputString = "aabaa", the output should be checkPalindrome(inputString) = true; For inputString = "abac", the output should be checkPalindrome(inputString) = false; For inputString = "a", the output should be checkPalindrome(inputString) = true. Input/Output [execution time limit] 20 seconds (swift) [input] string inputStringGuaranteed.. 2021. 5. 1.
Codesignal - bishop and pawn 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) = true. For .. 2021. 5. 1.
Codesignal - avoidObstacles You are given an array of integers representing coordinates of obstacles situated on a straight line. Assume that you are jumping from the point with coordinate 0 to the right. You are allowed only to make jumps of the same length represented by some integer. Find the minimal length of the jump enough to avoid all the obstacles. Example For inputArray = [5, 3, 6, 7, 9], the output should be avoi.. 2021. 4. 29.
Codesignal - arrayReplace Given an array of integers, replace all the occurrences of elemToReplace with substitutionElem. Example For inputArray = [1, 2, 1], elemToReplace = 1, and substitutionElem = 3, the output should be arrayReplace(inputArray, elemToReplace, substitutionElem) = [3, 2, 3]. Input/Output [execution time limit] 20 seconds (swift) [input] array.integer inputArray Guaranteed constraints: 0 ≤ inputArray.le.. 2021. 4. 29.
Codesignal - arrayMaximalAdjacentDifference Given an array of integers, find the maximal absolute difference between any two of its adjacent elements. Example For inputArray = [2, 4, 1, 0], the output should be arrayMaximalAdjacentDifference(inputArray) = 3. 설명 두 원소의 절대값 차이가 가장 큰값을 리턴해라 풀이 차이값을 저장할 빈배열 arr 선언 원소의 차이들을 arr에 저장하는데 차이가 마이너스 값이면 -1을 곱해준 값을 저장 arr 최대값 리턴 func arrayMaximalAdjacentDifference(inputArray: [Int]) -> Int { var arr =.. 2021. 4. 29.
Codesignal - arrayMaxConsecutiveSum 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. Input/Output [execution time limit] 20 seconds (swift) [input] array.int.. 2021. 4. 29.
300x250