1. Code
class Solution:
def deckRevealedIncreasing(self, deck: List[int]) -> List[int]:
id = deque(range(len(deck)))
output = [-1] * len(deck)
# It is a way of simulating the conditions of the problem as they are.
for e in sorted(deck):
output[id.popleft()] = e
if id: # If the list id is present, send the first element to the back.
id.append(id.popleft())
return output
2. Result
Runtime : 40 ms(92.20%), Memory usage : 14.3 MB(92.59%)
(Runtime can be different by a system even if it is a same code.)