본문 바로가기
728x90

알고리즘/코드시그널27

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.
Codesignal - arrayChange You are given an array of integers. On each move you are allowed to increase exactly one of its element by one. Find the minimal number of moves required to obtain a strictly increasing sequence from the input. Example For inputArray = [1, 1, 1], the output should be arrayChange(inputArray) = 3. 설명 배열 원소의 앞뒤 차이가 무조건 1이상 이어야 하며, 1이상 씩 증가시켰을 때 증가된 값과 기존값의 차이들을 합한 값을 리턴 풀이 인풋 배열을 복사하는 arr의 원소를 비교하고.. 2021. 4. 29.