Search
⌘K

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

Google


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Early October, 2024

Google

Google

Senior

Smallest String With Swaps

Your account is free and you can post anonymously if you choose.