Solution


Approach 1: Simulation

Intuition and Algorithm

Simulate the revealing process with a deck set to [0, 1, 2, ...]. If for example this deck is revealed in the order [0, 2, 4, ...] then we know we need to put the smallest card in index 0, the second smallest card in index 2, the third smallest card in index 4, etc.

Complexity Analysis

  • Time Complexity: , where is the length of deck.

  • Space Complexity: .


Analysis written by: @awice.