Problem:
Given array of integers, remove each kth element from it.
Example
For inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and k = 3, the output should be
extractEachKth(inputArray, k) = [1, 2, 4, 5, 7, 8, 10].
-Summary-
1. Create a 'ans' list for answer list
2. While loop을 돌리면서 index 가 지워지는 번호에 해당하지 않는경우 ans list에 넣어준다.
3. loop을 다 돌리면 지워지는 Kth index element만 지워진 'ans' list값을 return.
Additional Memory 를 만들어 문제를 풀었지만, 다른 사람이 submit한것을 보니 del() 함수를 이용하여 additional memory 를 쓰지 않고 in-place 로 바로 문제를 풀수 있었다.
del inputArray[k-1::k]
모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]
'CodeSignal > Arcade' 카테고리의 다른 글
CodeSignal [36/60] differentSymbolsNaive (0) | 2020.05.25 |
---|---|
CodeSignal [35/60] firstDigit (0) | 2020.05.25 |
CodeSignal [33/60] stringsRearrangement (1) | 2020.05.23 |
CodeSignal [32/60] absoluteValuesSumMinimization (0) | 2020.05.22 |
CodeSignal [31/60] depositProfit (0) | 2020.05.22 |
댓글