The Letter-Match Puzzle

Advanced

A word-game feature lets users check whether two words are built from exactly the same letters. Two strings match when each character appears the same number of times in both — order does not matter, but every letter must be accounted for. Build the check the feature calls on each guess.

Implement `solve(String a, String b)` to return true if `a` and `b` are anagrams (same characters with the same counts), false otherwise.

Examples

Inputa = "listen", b = "silent"
Outputtrue
Inputa = "apex", b = "apdx"
Outputfalse
Hints
  • Quick reject if the lengths differ.
  • Count characters of a, then subtract using characters of b; all counts must end at zero.
Anonymous Apex

Your code runs in a secure sandbox against multiple hidden test cases. The problem is solved only when every test passes. Each run is isolated and any data changes are rolled back automatically.