Stack Bash - Master data structures and algorithms

First unique character

Easy
Given a string of lowercase letters, write a function that returns the index of the first character that appears exactly once.
If every character repeats, return -1.
For example, given
s = "leetcode"
Your function should return 0, since l is the first unique letter.
Given
s = "aabb"
Your function should return -1.
The starter counts letters correctly, then walks the string backwards. Run it first.

Try it first

Solution

7 Essential DSA in the AI era Coding Interview Problems

Master DSA in the AI era by trying the coding challenges below.
  1. 1.Count occurrencesEasy
  2. 2.Fix the default listEasy
  3. 3.Move zeroesEasy
  4. 4.Is subsequenceEasy
  5. 5.First unique characterEasy
  6. 6.Group anagramsMedium
  7. 7.Climb stairsEasy