First loner
Inputs
text is 0 to 16 lowercase letters (a to f).
Your tasks
- Count how many times each letter appears: loop over
textand keep the counts in a list of 26 zeros, usingletter - "a"as the position. - Use a second loop over the positions of
text. Return the first position whose letter has a count of 1. - Complete
firstUniqueIndexso it returns that position, or -1 when every letter repeats. Return it, do not print it.
Example
With text = "aabcbd", firstUniqueIndex returns 3.
Rules
- Positions start at 0.
Test data
TEST DATA 1: text is "aabcbd"
TEST DATA 2: text is "aabb"
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.