FastPrepReveal Cards in Increasing Order

Reveal Cards in Increasing Order

NVIDIA logoNVIDIA● MediumFULLTIMEPHONE SCREEN

Updated

Problem statement

A deck contains cards with distinct positive integer values. Choose its starting order so the following process reveals the values in strictly increasing order:

  1. Reveal and remove the top card.
  2. If any cards remain, move the new top card to the bottom.
  3. Repeat until the deck is empty.

Return the starting deck as an array, with its top card first. Use every given card exactly once.

Function

deckRevealedIncreasing(deck: int[]) → int[]

Examples

Example 1

deck = [4,1,3,2]return = [1,3,2,4]

The reveal sequence is 1, 2, 3, 4 after moving each next top card to the bottom.

Example 2

deck = [5,12,7]return = [5,12,7]

Reveal 5, move 12 below 7, then reveal 7 and 12.

Example 3

deck = [8,2]return = [2,8]

Reveal 2, then reveal the remaining card 8.

Constraints

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

More NVIDIA Phone Screen questions

Similar questions at other companies

NVIDIA interview experiences

All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public int[] deckRevealedIncreasing(int[] deck) {
        // Write your code here.
    }
}
Checking account…