본문 바로가기
728x90

전체 글228

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.
Codesignal - areSimilar Two arrays are called similar if one can be obtained from another by swapping at most one pair of elements in one of the arrays. Given two arrays a and b, check whether they are similar. Example For a = [1, 2, 3] and b = ß[1, 2, 3], the output should be areSimilar(a, b) = true. The arrays are equal, no need to swap any elements. For a = [1, 2, 3] and b = [2, 1, 3], the output should be areSimila.. 2021. 4. 29.
Codesignal - areEquallyStrong Call two arms equally strong if the heaviest weights they each are able to lift are equal. Call two people equally strong if their strongest arms are equally strong (the strongest arm can be both the right and the left), and so are their weakest arms. Given your and your friend's arms' lifting capabilities find out if you two are equally strong. Example For yourLeft = 10, yourRight = 15, friends.. 2021. 4. 29.
Codesignal - alternatingSums Several people are standing in a row and need to be divided into two teams. The first person goes into team 1, the second goes into team 2, the third goes into team 1*again, the fourth into *team 2, and so on. You are given an array of positive integers - the weights of the people. Return an array of two integers, where the first element is the total weight of team 1, and the second element is t.. 2021. 4. 29.