Can you write a function to detect if two strings are anagrams (for example, SAVE and VASE)?

Submitted by: Muhammad
This is my go-to first interview question. It helps me gauge a candidate's ability to understand a problem and write an algorithm to solve it.

If someone has not solved the problem before, I expect to see some code with loops and if/then's. Maybe some HashMaps. The things I look for are ability to break down the problem to see what you need to check, what the edge cases are, and whether the code meets those criteria.

The naive solution is often to loop through the letters of the first string and see if they're all in the second string. The next thing to look for is, the candidate should also do that in reverse too (check string 1 for string 2's letters)? The next thing to look for is, what about strings with duplicate letters, like VASES?
Submitted by: Muhammad

Read Online Full Stack Developer (Java) Job Interview Questions And Answers