Skip to content

1061. Lexicographically Smallest Equivalent String #1770

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to find the lexicographically smallest equivalent string of baseStr by leveraging the equivalence information provided by s1 and s2. The equivalence between characters follows the properties of reflexivity, symmetry, and transitivity. The solution involves grouping equivalent characters into connected components and representing each component with the smallest lexicographical character.

Approach

  1. Union-Find Data Structure: We use the Union-Find (Disjoint Set Union, DSU) data structure to manage the equivalence relationships. This structure helps efficiently group characters into connected components where each component's root is the smallest character in the group.
  2. Initialization:…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Jun 5, 2025
Maintainer Author

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Jun 5, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jun 5, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants