2 ms·
No, it does. Once both strings are sorted alphabetically, you just compare them. "tallaf" -> sort -> "aafllt" "laftal" -> sort -> "aafllt" Does "aafllt" == "
by fallat 11y ago
No, it does. Once both strings are sorted alphabetically, you just compare them.
"tallaf" -> sort -> "aafllt"
"laftal" -> sort -> "aafllt"
Does "aafllt" == "aafllt" ? yes? Then we're good!
What you're saying:
"tallaffffff" -> sort -> "aaffffffllt"
"latfal" -> sort -> "aafllt"
Does "aaffffffllt" == "aafllt" ? Of course not.
The length check is just early exit. Actually for my solution the length is necessary.
Your solution is good too - I actually googled after to see other possible solutions and counting characters was the "second" solution.