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 Valid Anagram Lab
Strings
Problem shape
Beginner
4
8
15
16
23
42
Core idea
Count characters in one string and subtract counts using the other string.
Step 1 / 5
Problem shape
Strings Beginner
Valid Anagram
Welcome to the Valid Anagram algorithm lab. Count characters in one string and subtract counts using the other string. Use it when: Use when two strings must contain the same characters with the same frequencies. The time complexity is O(n), and the space complexity is O(k). The pseudocode is: if lengths differ return false count chars in first string for char in second string decrement count[char] return all counts are zero As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(n)
Space
O(k)
Pseudocode
if lengths differ return false
count chars in first string
for char in second string
decrement count[char]
return all counts are zero 1.0x