You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion was converted from issue #26 on September 15, 2026 10:59.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/couples-holding-hands/
Problem Summary
커플이 2n개의 좌석을 서로 붙어 있게 앉기 위한 최소의 스왑 횟수를 구하는 문제.
Solution
그리디하게 생각하면 의외로 쉽게 풀린다.
일단 앞에서 순차로 탐색한다고 해보면 짝이 안 맞는 사람이 있을 경우 뒤쪽에서 한 명이랑 스왑을 해줘야 한다. 그리고 이렇게 스왑을 한 경우 이 커플은 더 이상 스왑을 해줄 필요가 없어진다.
이렇게 순차적으로 커플이 되도록 스왑을 쭉 돌려주면 되는 문제.
Source Code
All reactions