Arrange a Deck for Increasing Reveal-and-Rotate Order

Quick Overview

Arrange a Deck for Increasing Reveal-and-Rotate Order. Reorder the unique card values in deck so this procedure reveals them in increasing order: remove and reveal the top card, then move the next top card to the bottom if any cards remain, and repeat.

Arrange a Deck for Increasing Reveal-and-Rotate Order

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Reorder the unique card values in `deck` so this procedure reveals them in increasing order: remove and reveal the top card, then move the next top card to the bottom if any cards remain, and repeat. The first returned array entry is the top card. ```cpp class Solution { public: vector<int> deckRevealedIncreasing(vector<int>& deck); }; ``` ### Examples **Example 1:** ```text Input: deck = [5,1,3,2] Output: [1,3,2,5] Explanation: Revealing1 and rotating3 leaves[2,5,3]; revealing2 and rotating5 leaves[3,5], followed by3 and5. ``` **Example 2:** ```text Input: deck = [6,2,4] Output: [2,6,4] Explanation: Reveal2, rotate6 below4, then reveal4 and6. ``` ### Constraints - `1 <= deck.length <= 1000`. - `1 <= deck[i] <= 10^6`. - All values are unique. ### Contract considerations All card values are unique. No special ordering of the input deck is promised. ```hint Read the boundary condition Simulate the process on position labels before placing the sorted card values. ``` ### Boundary reminders All card values are unique. No special ordering of the input deck is promised.

Overview: Arrange a Deck for Increasing Reveal-and-Rotate Order. Reorder the unique card values in deck so this procedure reveals them in increasing order: remove and reveal the top card, then move the next top card to the bottom if any cards remain, and repeat.

Google logo
Google
Jun 23, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Reorder the unique card values in deck so this procedure reveals them in increasing order: remove and reveal the top card, then move the next top card to the bottom if any cards remain, and repeat. The first returned array entry is the top card.

class Solution {
public:
    vector<int> deckRevealedIncreasing(vector<int>& deck);
};

Examples

Example 1:

Input: deck = [5,1,3,2]
Output: [1,3,2,5]
Explanation: Revealing1 and rotating3 leaves[2,5,3]; revealing2 and rotating5 leaves[3,5], followed by3 and5.

Example 2:

Input: deck = [6,2,4]
Output: [2,6,4]
Explanation: Reveal2, rotate6 below4, then reveal4 and6.

Constraints

  • 1 <= deck.length <= 1000 .
  • 1 <= deck[i] <= 10^6 .
  • All values are unique.

Contract considerations

All card values are unique. No special ordering of the input deck is promised.

Boundary reminders

All card values are unique. No special ordering of the input deck is promised.