본문 바로가기
300x250

전체 글244

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.
Codesignal - alphabeticShift Given a string, your task is to replace each of its characters by the next one in the English alphabet; i.e. replace a with b, replace b with c, etc (z would be replaced by a). Example For inputString = "crazy", the output should be alphabeticShift(inputString) = "dsbaz". 설명 inputString의 각 문자를 알파벳 순서에 맞게 다음 알파벳으로 바꿔라 풀이 문자열의 각 문자들을 인코딩한 값에 1을 더하여 아스키코드에 맞는 문자를 리턴 func alphabeticShift(inputString.. 2021. 4. 29.
Codesignal - almostIncreasingSequence Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array. Note: sequence a0, a1, ..., an is considered to be a strictly increasing if a0 < a1 < ... < an. Sequence containing only one element is also considered to be strictly increasing. Example For sequence = [1, 3, 2, 1], the output sh.. 2021. 4. 29.
300x250