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

DS

Arrays and prefix sums

Find the sum of the supplied zero-based interval. Include both endpoints.

Beginner
DS

Big O and growth

Two independent loops each visit every item in a list. Count the total visits and give the time bound.

Beginner
DS

Linear search

Find the first shelf position with the requested label. Use zero-based indexing and -1 for a missing label.

Beginner
DS

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.

Beginner
DS

Bubble sort

Show the array after exactly one full pass of bubble sort, starting on the left.

Beginner
DS

Stacks and undo

Read the top value after performing the listed operations, or return "Empty".

Beginner
DS

Queues and arrival order

List the jobs removed in order. Return "Empty" for a removal when no job is waiting.

Beginner
DS

Two pointers

Which distinct pair reaches the target?

Beginner
DS

Sliding windows

What is the largest window sum?

Beginner
DS

Singly linked lists

Insert B after A and report the resulting node order.

Intermediate
DS

Hash maps and counting

Return the first label seen a second time, or "None" if all labels are unique.

Intermediate
DS

Recursion and tree traversal

Count all nodes in each tree. A missing child contributes zero.

Intermediate
DS

Breadth-first search

Starting at A, list visited vertices. Process each vertex’s neighbors alphabetically and treat the edges as undirected.

Intermediate
DS

Depth-first search

List the DFS visit order starting from A. Visit available neighbors in alphabetical order and use undirected edges.

Intermediate
DS

Backtracking with choices

List every two-letter string with no duplicates, exploring letters in the order given.

Intermediate
DS

Merge sort

What two sorted halves are merged in the final step?

Intermediate
DS

Quicksort and partitioning

Which three groups does a three-way partition produce?

Intermediate
DS

Heaps and priority queues

Which priority is exposed at the top next?

Intermediate
DS

Binary search trees

Which keys are visited when searching for 5?

Intermediate
DS

Algorithm invariants

What should total be before processing the third item?

Intermediate