Given a row of people sitting in seats, return the minimum number of swaps needed so that each couple sits together. DSU can group seats by connected couple relationships and count how many swaps each component requires.
row = people seated in order
minimum number of swaps required
Example 1:
Input:
row = [0,2,1,3]
Output:
1
Explanation:
Swapping 2 and 1 places both couples together.
Example 2:
Input:
row = [3,2,0,1]
Output:
0
Explanation:
Each couple is already seated together.
Example 3:
Input:
row = [0,1,2,3]
Output:
0
Explanation:
All couples are already adjacent.