> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Reveal Cards In Increasing Order

> Tested Python solution for LeetCode 950 with 12 pytest cases. Generate a practice environment with lcpy.

LeetCode 950, [Medium](/catalog/medium). Topics: [Array](/catalog/topics/array), [Queue](/catalog/topics/queue), [Sorting](/catalog/topics/sorting), [Simulation](/catalog/topics/simulation). [View on LeetCode](https://leetcode.com/problems/reveal-cards-in-increasing-order/description/).

Generate this problem as a practice environment: tested reference solution, 12 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 950   # by problem number
lcpy gen -s reveal_cards_in_increasing_order   # by problem name
```

## Problem

\<p>You are given an integer array \<code>deck\</code>. There is a deck of cards where every card has a unique integer. The integer on the \<code>i\<sup>th\</sup>\</code> card is \<code>deck\[i]\</code>.\</p>

\<p>You can order the deck in any order you want. Initially, all the cards start face down (unrevealed) in one deck.\</p>

\<p>You will do the following steps repeatedly until all cards are revealed:\</p>

\<ol>
\<li>Take the top card of the deck, reveal it, and take it out of the deck.\</li>
\<li>If there are still cards in the deck then put the next top card of the deck at the bottom of the deck.\</li>
\<li>If there are still unrevealed cards, go back to step 1. Otherwise, stop.\</li>
\</ol>

\<p>Return \<em>an ordering of the deck that would reveal the cards in \<strong>increasing\</strong> order\</em>.\</p>

\<p>\<strong>Note\</strong> that the first entry in the answer is considered to be the top of the deck.\</p>

### Examples

```
Input: deck = [17,13,11,2,3,5,7]
Output: [2,13,3,11,5,17,7]
Explanation: We get the deck in the order [17,13,11,2,3,5,7] (this order does not matter), and reorder it.
```

```
Input: deck = [1,1000]
Output: [1,1000]
```

### Constraints

* 1 \<= deck.length \<= 1000
* 1 \<= deck\[i] \<= 10^6
* All the values of deck are unique.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/reveal_cards_in_increasing_order/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/reveal_cards_in_increasing_order/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from collections import deque


class Solution:
    # Time: O(n log n)
    # Space: O(n)
    def deck_revealed_increasing(self, deck: list[int]) -> list[int]:
        queue: deque[int] = deque(range(len(deck)))
        result: list[int] = [0] * len(deck)
        for card in sorted(deck):
            # Reveal the card at the front position
            result[queue.popleft()] = card
            # Move the next position to the bottom
            if queue:
                queue.append(queue.popleft())
        return result
```

## Complexity

| Time | Space |
| - | - |
| O(n log n) | O(n) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.