Skip to content

Commit d80bcc5

Browse files
committed
Create README - LeetHub
1 parent 9912743 commit d80bcc5

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

couples-holding-hands/README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<h2>765. Couples Holding Hands</h2><h3>Hard</h3><hr><div><p>There are <code>n</code> couples sitting in <code>2n</code> seats arranged in a row and want to hold hands.</p>
2+
3+
<p>The people and seats are represented by an integer array <code>row</code> where <code>row[i]</code> is the ID of the person sitting in the <code>i<sup>th</sup></code> seat. The couples are numbered in order, the first couple being <code>(0, 1)</code>, the second couple being <code>(2, 3)</code>, and so on with the last couple being <code>(2n - 2, 2n - 1)</code>.</p>
4+
5+
<p>Return <em>the minimum number of swaps so that every couple is sitting side by side</em>. A swap consists of choosing any two people, then they stand up and switch seats.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong>Example 1:</strong></p>
9+
10+
<pre><strong>Input:</strong> row = [0,2,1,3]
11+
<strong>Output:</strong> 1
12+
<strong>Explanation:</strong> We only need to swap the second (row[1]) and third (row[2]) person.
13+
</pre>
14+
15+
<p><strong>Example 2:</strong></p>
16+
17+
<pre><strong>Input:</strong> row = [3,2,0,1]
18+
<strong>Output:</strong> 0
19+
<strong>Explanation:</strong> All couples are already seated side by side.
20+
</pre>
21+
22+
<p>&nbsp;</p>
23+
<p><strong>Constraints:</strong></p>
24+
25+
<ul>
26+
<li><code>2n == row.length</code></li>
27+
<li><code>2 &lt;= n &lt;= 30</code></li>
28+
<li><code>n</code> is even.</li>
29+
<li><code>0 &lt;= row[i] &lt; 2n</code></li>
30+
<li>All the elements of <code>row</code> are <strong>unique</strong>.</li>
31+
</ul>
32+
</div>

0 commit comments

Comments
 (0)