Couples Holding Hands
N couples sit in 2N seats arranged in a row. You want every couple to sit side by side. Couples are numbered (0,1), (2,3), etc. A swap consists of choosing any two people and having them swap seats. Return the minimum number of swaps so that every couple is sitting side by side.

30:00

Couples Holding Hands
hard
Topics
Companies

N couples sit in 2N seats arranged in a row. You want every couple to sit side by side. Couples are numbered (0,1), (2,3), etc. A swap consists of choosing any two people and having them swap seats. Return the minimum number of swaps so that every couple is sitting side by side.

Example 1:
Input: {"row":[0,2,1,3]}
Output: 1
Constraints:
  • 2n==row.length2n == \text{row.length}

  • 2n302 \leq n \leq 30

  • nn is even.

  • 0row[i]<2n0 \leq \text{row}[i] < 2n

  • All elements of row are unique.

Input
arr ={"row":[0,2,1,3]}

Row: [0, 2, 1, 3]

Couples on Couch (paired people share color)

0

seat 0

2

seat 1

1

seat 2

3

seat 3

Couple (0, 1)

Couple (2, 3)

Swaps:

0

Variables
No variables to display
DepthFunction Call
Stack empty
0/1