Similar String Groups
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Call two strings x and y **similar** if they are identical, or if exchanging the characters at exactly two positions of x turns it into y.
You are given a list strs in which every string is a rearrangement (anagram) of every other string, so all have the same length. Similarity links strings together: a **group** is a maximal set of strings where any two are connected by a chain of similar pairs (similarity itself is not transitive, but group membership is).
Return the number of groups. Identical strings always land in the same group.
Examples
Constraints
- 1 <= strs.length <= 300
- 1 <= strs[i].length <= 300
- strs[i] consists of lowercase English letters
- All strings in strs are anagrams of each other
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.