Leetcode 2948. Make Lexicographically Smallest Array by Swapping Elements
You may swap two indices iff their values differ by at most limit; compute the lexicographically smallest array obtainable by any sequence of such swaps. Equivalently, build a graph connecting indices with |nums[i]-nums[j]| ≤ limit, find each connected component, and sort/reassign its values so the smallest numbers occupy the smallest indices.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
0
Hello Interview Premium
Your account is free and you can post anonymously if you choose.