Classic Coding Problems interview questions

The problems that keep showing up in online tests and live rounds: primes, spiral matrix, two sum, linked lists, stacks, binary search and array partitioning, each explained step by step.

Readiness: 0 of 34 nailed

How to use this page: 1. Read a question2. Type your answer3. Check with AI4. Open the model answer5. Timed drill when you’re 70% ready

Math

FoundationWrite it by hand

Print all prime numbers up to n. Then: all primes between a and b.

FoundationWrite it by hand

Swap two variables without using a temporary variable.

JuniorWrite it by hand

Check whether three points are on the same straight line.

Arrays

FoundationWrite it by hand

Two Sum: return the indices of two numbers that add up to target.

JuniorWrite it by hand

Print a matrix in spiral order.

JuniorWrite it by hand

Rearrange an array so all elements less than x come before the rest, in place.

JuniorWrite it by hand

An array holds numbers 1 to n with one missing. Find it in O(n) time and O(1) space.

Mid-levelWrite it by hand

Find the largest sum of a contiguous subarray (Kadane’s algorithm).

FoundationWrite it by hand

Merge two sorted arrays into one sorted array.

JuniorWrite it by hand

Rotate an array to the right by k steps in place.

Mid-levelWrite it by hand

Merge overlapping intervals like [[1,3],[2,6],[8,10]].

Linked lists

JuniorWrite it by hand

Reverse a singly linked list.

Mid-levelWrite it by hand

Delete a node from a singly linked list when you only have a pointer to that node (not the head).

Mid-levelWrite it by hand

Detect whether a linked list has a cycle.

Stacks and queues

FoundationWrite it by hand

Check whether a string of brackets like {[()]} is balanced.

Mid-levelWrite it by hand

Implement a queue using two stacks.

Mid-levelWrite it by hand

Design a stack that returns the minimum element in O(1).

Searching and sorting

Mid-levelWrite it by hand

Find the kth largest element in an array.

JuniorConcept

Compare bubble sort, merge sort and quicksort.

Strings

FoundationWrite it by hand

Check whether two words are anagrams (listen / silent).

FoundationWrite it by hand

Find the first non-repeating character in a string.

Mid-levelWrite it by hand

Group words that are anagrams of each other.

FoundationWrite it by hand

Check whether a sentence is a palindrome, ignoring case and punctuation, using two pointers.

Recursion and DP

FoundationWrite it by hand

Return the nth Fibonacci number efficiently.

JuniorWrite it by hand

You can climb 1 or 2 steps at a time. How many ways to climb n steps?

SeniorWrite it by hand

Find the minimum number of coins to make an amount.

Sliding window

Mid-levelWrite it by hand

Find the length of the longest substring without repeating characters.

Graphs and trees

JuniorConcept

BFS vs DFS: what’s the difference, and when do you use each?

FoundationWrite it by hand

Find the maximum depth of a binary tree.

Mid-levelWrite it by hand

Check whether a binary tree is a valid binary search tree.

JuniorWrite it by hand

Print a binary tree level by level.

Mid-levelWrite it by hand

Count the islands in a grid of 1s (land) and 0s (water).

Design

SeniorWrite it by hand

Design an LRU cache with O(1) get and put.

Also prepare