Grokking Data Structures & Algorithms for Coding Interviews
Vote

0% completed

​

Solution: First Non-repeating Character (easy)

.....

.....

.....

Like the course? Get enrolled and start learning!
A

Anonymous

· 2 years ago

Should space complexity be O(n)?

A

Anonymous

· 3 years ago

In Python, we could take advantage of the Counter() class from the 'collections' library to get the frequency of each character instead of doing it manually. Any tips for improving the following candidate solution would be great:

from collections import Counter class Solution: def firstUniqChar(self, s: str) -> int: characters_count = Counter(s) for index, character in enumerate(s): if characters_count[character] == 1: return index return -1

Reading Progress

0%


Vote for new content