Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Sort both strings alphabetically and compare. If they are anagrams, their sorted forms will be identical. This is simpler than the hash map approach but trades O(n) time for O(n log n) due to sorting.
Anagrams are permutations of the same characters. Sorting normalizes any permutation to a canonical form, so two anagrams produce identical sorted strings. The tradeoff vs frequency counting: simpler code but slower for large inputs.
Updated Feb 2026