cswork / OAOpen practice workspace

PlaidOA #2

Min Shuffle Moves to Sort Deck

Estimated EasyStatement and editorial — judging is being prepared

Topics (AI-labelled)In-place Arrays

You have a deck of cards numbered from 1 to n. The cards are currently in some order; you want to sort them ascending. The only operation: take k cards from the top of the deck and move them to the bottom (k ∈ [0, n-1]). Return the minimum number of cards k to move, or -1 if impossible.

  • deck = [1, 4, 2, 3] → -1
  • deck = [3, 4, 5, 1, 2] → 3

Editorial

Loading solution…