Leetcode 1202. Smallest String With Swaps
Given a string and allowed index swap pairs, view pairs as edges in a graph to find connected components where characters can be freely permuted; for each component, sort its characters and place them in the component's indices to produce the lexicographically smallest string. This requires near-linear component-finding (union-find or DFS) and sorting per component to handle up to 1e5 elements.
Asked at:
Google
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
0
Early October, 2024
Senior
Smallest String With Swaps
Hello Interview Premium
Your account is free and you can post anonymously if you choose.