Same letters
Inputs
a and b are 0 to 12 lowercase letters (a to e).
Your tasks
- Create a list
countsof 26 zeros. - Use a loop over
ato add 1 to each letter's count, then a loop overbto take 1 away. - Check that every count is 0.
- Complete
sameLettersso it returns true whenbuses exactly the same letters asa, in any order, otherwise false. Return it, do not print it.
Example
With a = "listen" and b = "silent", sameLetters returns true.
Rules
- Two empty texts match.
Test data
TEST DATA 1: a is "listen", b is "silent"
TEST DATA 2: a is "abc", b is "abd"
Practice focus
Prefix sums, counting, binary search, best stretch and sorting, all written as plain loops. This is where loops turn into named algorithms. You have already written the loops.