Notice
Recent Posts
Recent Comments
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

CHIqueen

[Intro] Make Array Consecutive 2 본문

프로그래밍/CodeSignal

[Intro] Make Array Consecutive 2

CHIqueen 2020. 3. 3. 18:01

Ratiorg got statues of different sizes as a present from CodeMaster for his birthday, each statue having an non-negative integer size. Since he likes to make things perfect, he wants to arrange them from smallest to largest so that each statue will be bigger than the previous one exactly by 1. He may need some additional statues to be able to accomplish that. Help him figure out the minimum number of additional statues needed.

 

Example

For statues = [6, 2, 3, 8], the output should be
makeArrayConsecutive2(statues) = 3.

Ratiorg needs statues of sizes 4, 5 and 7.

 

def makeArrayConsecutive2(statues):
    return max(statues) - min(statues) - len(statues) + 1

최대와 최소의 범위내에서 각 요소들 수를 뺀다음 1을 더해줬더니 답이 되었다.

'프로그래밍 > CodeSignal' 카테고리의 다른 글

[Intro] matrixElementsSum  (0) 2020.03.11
[Intro] shapeArea  (0) 2020.03.03
[Intro] adjacentElementsProduct  (0) 2020.03.03
[Intro] checkPalindrome  (0) 2020.02.26
[Intro] centuryFromYear  (0) 2020.02.26
Comments