Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Smallest String With Swaps

You are given a string and pairs of indices; any two characters at paired indices may be swapped any number of times. Print the lexicographically smallest string you can obtain.

Constraints

1 <= len(s) <= 10^5 0 <= p <= 10^5

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.