Practice problems
Choose a topic, work through an example, and reveal a hint or worked answer when you’re ready.
Showing 1–20 of 35 problems
Arrays and prefix sums
Find the sum of the supplied zero-based interval. Include both endpoints.
Big O and growth
Two independent loops each visit every item in a list. Count the total visits and give the time bound.
Linear search
Find the first shelf position with the requested label. Use zero-based indexing and -1 for a missing label.
Binary search
A library shelf displays sorted copy numbers. Return the zero-based index of a requested number, or -1 if the copy is absent.
Bubble sort
Show the array after exactly one full pass of bubble sort, starting on the left.
Stacks and undo
Read the top value after performing the listed operations, or return "Empty".
Queues and arrival order
List the jobs removed in order. Return "Empty" for a removal when no job is waiting.
Two pointers
Which distinct pair reaches the target?
Sliding windows
What is the largest window sum?
Singly linked lists
Insert B after A and report the resulting node order.
Hash maps and counting
Return the first label seen a second time, or "None" if all labels are unique.
Recursion and tree traversal
Count all nodes in each tree. A missing child contributes zero.
Breadth-first search
Starting at A, list visited vertices. Process each vertex’s neighbors alphabetically and treat the edges as undirected.
Depth-first search
List the DFS visit order starting from A. Visit available neighbors in alphabetical order and use undirected edges.
Backtracking with choices
List every two-letter string with no duplicates, exploring letters in the order given.
Merge sort
What two sorted halves are merged in the final step?
Quicksort and partitioning
Which three groups does a three-way partition produce?
Heaps and priority queues
Which priority is exposed at the top next?
Binary search trees
Which keys are visited when searching for 5?
Algorithm invariants
What should total be before processing the third item?