Couples Holding Hands

Couples Holding Hands

There are n couples sitting in 2n seats arranged in a row. The people and seats are represented by an integer array row where row[i] is the ID of the person sitting in the i-th seat. The couples are defined by their IDs: the first couple is (0, 1), the second couple is (2, 3), and so on, with the last couple being (2n - 2, 2n - 1). You want to rearrange the people so that every couple is sitting side by side (i.e., in seats (0, 1), (2, 3), \dots). A single swap consists of choosing any two people currently in seats and having them switch places. Return the minimum number of swaps required to achieve this state. Constraints: 2n == row.length 2 <= n <= 30 row is a permutation of [0, 2n - 1].
JavaGreedyUnion-Find
00
Read
1
InterviewGPT

AI-powered tools to help you succeed in tech interviews — from resume to offer.

Interview Solver

  • Coding Puzzles
  • System Design
  • Behavioral Challenges
  • ML System Design
  • SQL Puzzles
  • FE System Design
Explore Solver

Question Bank

  • Coding Interview Questions
  • System Design Interview Questions
  • Behavioral Interview Questions
  • ML System Design Questions
  • SQL & Database Questions
  • FE System Design Questions
Explore Questions

Golden Blogs

  • Coding Solutions
  • System Design Guides
  • Behavioral Guides
  • ML System Design Guides
  • SQL Solutions
  • FE System Design Guides
Explore Blogs

Intervipedia

  • Coding Concepts
  • System Design Concepts
  • Behavioral Concepts
  • ML System Concepts
  • SQL Concepts
  • FE System Concepts
Explore Concepts

Application Tools

  • Self-Intro Generator

Company

  • Pricing
  • FAQ
  • About
  • Privacy Policy
  • Terms of Service

© 2026 InterviewGPT Inc. All rights reserved.

All systems operationalUS-East

Made with ♥ for developers