이경로 2022. 11. 25. 00:21

Difficulty : Platinum V

Problem Description

There are 'N' numbers, and you have to sort them which are never continuous.

If there are several answers, choose the first one by alphabetical order.

 

Solution

 

'N' is the number of numbers.

'l' is the list of numbers. Sort 'l' to solve the problem.

'a' is the output list, and -2 means that all the first number can be appended to 'a'.

'i' is the index of 'l'.

 

While 'l' is not empty, repeat the sequence.

There are three cases that I have to manage.

7~9 : If the last number is the sum of the first number and 1, the list will have this shape. '[x, ..., x, x+1, ..., x+1]'

         So all 'x+1' must be the front, and all 'x' must be behind. Append the last number from 'l' to 'a'.

10~11 : If 'a[-1]+1 is equal to 'l[i]', 'l[i]' can't be appended to 'a'. So increase the index.

12~15 : If the sequence is not included in both case, just append 'l[i]' from 'l' to 'a'.

 

여담

약간의 객기로 플래티넘 문제에 도전해 봤는데 생각보다 쉽게 풀렸다. 하지만 문제 유형별로 격차가 매우 커서(그래프는 실버 수준) 어쩌다가 한 번씩 풀 정도 인것 같다.