Exchange Cups

Problem Overview

  • Given N cups labeled 1..N and their current order, compute the minimum number of pair swaps needed to sort them to 1..N.
  • Input: N (N < 10000) and a sequence of N positive integers; Output: one integer, the least swap count.
  • Real-world context: reorganizing items on a store shelf using two-at-a-time exchanges.
  • From TikTok interviews; a coding interview problem often presented as an interview question on arrays and permutations.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: