Skip to content
LC-0950 Medium LeetCode

950. Reveal Cards In Increasing Order

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 83% Topics: Array, Queue, Sorting, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(n)

import collections


class Solution(object):
    def deckRevealedIncreasing(self, deck):
        """
        :type deck: List[int]
        :rtype: List[int]
        """
        d = collections.deque()
        deck.sort(reverse=True)
        for i in deck:
            if d:
                d.appendleft(d.pop())
            d.appendleft(i)
        return list(d)

Solution from kamyu104/LeetCode-Solutions · MIT