Practice problems
Choose a topic, work through an example, and reveal a hint or worked answer when you’re ready.
Showing 21–35 of 35 problems
DSIntermediateDSIntermediateDSAdvancedDSAdvancedDSAdvancedDSAdvancedDSAdvancedDSAdvancedDSAdvancedDSAdvancedDSAdvancedDSAdvancedDSAdvancedDSAdvancedDSAdvanced
Adjacency lists and matrices
Which neighbor lists change?
Counting sort
What are the counts for 0, 1, 2, and 3?
Dijkstra’s shortest paths
Find the cost of the cheapest route from A to B along the listed directed edges.
Dynamic programming
Count ordered ways to climb exactly n stairs, using one- or two-stair moves.
Tries and prefix search
Is ca a stored word, a prefix, or both?
Union-find and connected groups
Which items share a group with A?
Topological sorting
Give one valid order.
Greedy interval scheduling
Which intervals does earliest finish select?
Minimum spanning trees
What is the cost of the minimum spanning tree?
Bellman–Ford and negative edges
What distance should replace 8?
0/1 knapsack
What is the highest value?
Longest common subsequence
Give a longest common subsequence.
Fenwick trees and dynamic prefix sums
Which indexes are read using i -= i & -i?
Segment trees and range queries
What is the new sum at the root?
Monotonic stacks
What is the next greater value for 1?