First Unique Character in a String
We want to find the index of the first character in a string that does not later repeat itself.
We break out a frequency map, an empty object that we will use to store the characters of a string we loop through. If the character is already in the frequency map, we add it to a count. If this is the character's first appearance, we set its' count to 1.
Once everything has been counted and sorted, we can run the original string through a loop, and at each index, we will compare how many times this index of the string, aka character, appears in the frequency map. We are looking for it to match the number one. If it does, we return this index. If it never matches, we return a negative one.
Software Engineer | CompTIA Security+ Certified | 3x AWS Certified (Practitioner, Developer, and Solutions Architect)
1 年DUDE this is so insightful, thank you for posting! Really helpful way of breaking it down.
Client Solutions Manager
1 年I love the colors!