1/20/2024
Lexicographically Smallest Equivalent String
This is my solution for the problem Lexicographically Smallest Equivalent String on Leetcode.
This is the third problem I did on Leetcode in this streak and the second Union-Find problem. I can recognize some improvement on my part. I can reason and do it on my own without looking at the solution.
There are some differences in this problem. Firstly, I cannot use path compression because the criteria of merging is to merge the group with the higher root into the group with the lower root to ensure the root is always the lexicographically smallest character in the group. Secondly, there are some extra preparations before the union. It is because I want to work with the indices, not the characters. So, I need a way to translate between the two. It turns out that the algorithm is the same, but the data is different, and we need to translate them into something that is easier to work with.