Problem 1202 · Medium

Smallest String With Swaps

Given a string and pairs of indices whose characters may be swapped freely, return the smallest string that can be reached. The visual groups indices into connected components and sorts the letters within each group.

Open the interactive visualisation