Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB First Non-Repeating Character Lab
Strings
Problem shape
Beginner
4
8
15
16
23
42
Core idea
Count frequencies, then scan again to find the first count of one.
Step 1 / 5
Problem shape
Strings Beginner
First Non-Repeating Character
Welcome to the First Non-Repeating Character algorithm lab. Count frequencies, then scan again to find the first count of one. Use it when: Use when position and uniqueness both matter. The time complexity is O(n), and the space complexity is O(k). The pseudocode is: count every character for i from 0 to n - 1 if count[s[i]] == 1 return i return -1 As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(n)
Space
O(k)
Pseudocode
count every character
for i from 0 to n - 1
if count[s[i]] == 1
return i
return -1 1.0x