ToolMight Logo

DSA Interview Problems & Coding Patterns

Study 31 core interview problems grouped by algorithmic pattern. Each problem compares brute-force and optimal complexity, walks through concrete execution traces, highlights boundary edge cases, and provides implementations in Python, JavaScript, Java, C++, and C.

Problem Set
31 Problems · 10 Patterns
Difficulty Split
16E / 14M / 1H
Languages
Python, JS, Java, C++, C
Companion Simulators
35 DSA Visualizers →

Browse Problems

Filter by pattern, difficulty, or study status to inspect complexity trade-offs, trace steps, and implementations.

Local Study Progress0/31 solved
Showing 31 problems
EasyArrays & Hashing

Two Sum

Find indices of two array elements summing to target. Compare O(n²) brute-force scanning against O(n) one-pass complement lookup with a Hash Map.

Pattern: Hash Map
O(n) · O(n)
Solve
EasyArrays & Hashing

Contains Duplicate

Check whether any integer repeats inside an array. Compare early-exit O(n) Hash Set membership testing against O(1)-space in-place sorting.

Pattern: Hash Set
O(n) · O(n)
Solve
EasyArrays & Hashing

Valid Anagram

Check whether string t is an anagram of string s. Compare O(n log n) canonical sorting against an O(n) fixed 26-letter frequency bucket balance.

Pattern: Frequency Counting
O(n) · O(1)
Solve
MediumArrays & Hashing

Product of Array Except Self

Compute the array of products excluding each element without division. Progress from separate left/right product arrays to O(1) auxiliary space.

Pattern: Prefix and Suffix Products
O(n) · O(1)
Solve
MediumArrays & Hashing

Top K Frequent Elements

Extract the k most frequent integers in an array. Compare a size-K Min-Heap over frequency counts with O(n) frequency-indexed Bucket Sort.

Pattern: Bucket Sort
O(n) · O(n)
Solve
EasyArrays & Hashing

Linear Search

Locate a target value inside an unsorted array by scanning elements sequentially. Compare standard index-bounded scanning with Sentinel Loop optimization.

Pattern: Sequential Scan
O(n) · O(1)
Solve
EasyBinary Search

Binary Search

Locate a target value in a sorted array in O(log n) time by repeatedly bisecting the search interval. Compare iterative vs recursive implementations and overflow guards.

Pattern: Divide and Conquer
O(log n) · O(1)
Solve
MediumBinary Search

Search in Rotated Sorted Array

Locate a target inside a rotated sorted array in O(log n) time. Compare pivot-split binary search against single-pass sorted-half elimination.

Pattern: Modified Binary Search
O(log n) · O(1)
Solve
EasyTwo Pointers

Valid Palindrome

Check whether a string reads identically forward and backward over alphanumeric characters. Compare build-and-reverse against O(1)-space converging pointers.

Pattern: Two Pointers Converging
O(n) · O(1)
Solve
MediumTwo Pointers

3Sum

Find all unique integer triplets summing to zero. Compare hash-set pair lookup against sorting + two-pointer inward scans with duplicate skipping.

Pattern: Sort then Two Pointers
O(n²) · O(1) to O(n)
Solve
MediumTwo Pointers

Container With Most Water

Find two vertical walls bounding maximum water volume. Compare quadratic pair enumeration against O(n) greedy two-pointer elimination.

Pattern: Two Pointers Inward Convergence
O(n) · O(1)
Solve
HardTwo Pointers

Trapping Rain Water

Calculate total trapped water between elevation bars. Compare O(n)-space prefix/suffix max arrays with O(1)-space converging two pointers.

Pattern: Two Pointers Max Boundaries
O(n) · O(1)
Solve
MediumSliding Window

Longest Substring Without Repeating Characters

Find the longest contiguous substring with all distinct characters. Compare shrinking-set sliding windows against O(1) direct left-pointer jumps via an index map.

Pattern: Dynamic Sliding Window
O(n) · O(min(n, m))
Solve
EasyStack

Valid Parentheses

Check whether brackets (), {}, and [] match in proper nested LIFO order. Compare iterative innermost-pair collapse against O(n) stack validation.

Pattern: Last-In First-Out (LIFO)
O(n) · O(n)
Solve
MediumStack

Min Stack

Design a LIFO stack supporting push, pop, top, and getMin in O(1) time. Compare a synchronized parallel min stack against a sparse minimum-change stack.

Pattern: Auxiliary Min Tracking
O(1) for all operations · O(n)
Solve
EasyLinked List

Reverse Linked List

Reverse a singly linked list in-place by flipping next pointers. Compare O(1)-space three-pointer iteration with recursive tail rewiring.

Pattern: Pointer Reversal
O(n) · O(1)
Solve
EasyLinked List

Merge Two Sorted Lists

Splice two sorted linked lists together into one non-decreasing linked list. Compare O(1)-space iterative dummy-head splicing against recursive pointer linking.

Pattern: Dummy Head
O(n + m) · O(1)
Solve
EasyLinked List

Linked List Cycle

Detect whether a linked list loops back on itself. Compare O(n)-space node-identity tracking against Floyd's O(1)-space fast-and-slow pointer algorithm.

Pattern: Fast and Slow Pointers
O(n) · O(1)
Solve
EasyTrees & BST

Invert Binary Tree

Mirror a binary tree around its vertical axis by swapping left and right child pointers via recursive DFS or iterative level-order BFS.

Pattern: DFS Traversal
O(n) · O(h)
Solve
EasyTrees & BST

Maximum Depth of Binary Tree

Compute the maximum depth (node count along longest root-to-leaf path) of a binary tree using recursive post-order DFS and iterative level-order BFS.

Pattern: Depth-First Search (DFS)
O(n) · O(h)
Solve
EasyTrees & BST

Subtree of Another Tree

Check whether subRoot matches an entire subtree of root in structure and values. Compare double-DFS tree matching against O(n + m) pre-order serialization + substring search.

Pattern: Tree Traversal DFS
O(n * m) · O(h)
Solve
MediumTrees & BST

Binary Tree Level Order Traversal

Group binary tree node values level-by-level from left to right. Compare FIFO queue level batching against depth-indexed DFS recursion.

Pattern: Breadth-First Search (BFS)
O(n) · O(w)
Solve
EasyTrees & BST

Lowest Common Ancestor of a Binary Search Tree

Locate the lowest common ancestor of nodes p and q inside a Binary Search Tree. Compare recursive BST branching against an O(1)-space iterative root-to-split walk.

Pattern: BST Invariant Traversal
O(h) · O(1)
Solve
MediumGraphs & Matrix Walks

Number of Islands

Count disconnected landmasses across a 2D binary grid using connected-component traversal. Compare in-place DFS flood fill against iterative BFS.

Pattern: Depth-First Search (DFS)
O(m * n) · O(m * n)
Solve
MediumGraphs & Matrix Walks

Rotting Oranges

Find minimum minutes for all fresh oranges to rot via 4-directional spreading. Compare in-place O(1)-space round simulation with optimal Multi-Source BFS.

Pattern: Multi-Source BFS
O(m * n) · O(m * n)
Solve
MediumHeap & Priority Queue

Kth Largest Element in an Array

Locate the kth largest integer in an unsorted array without full sorting. Compare a size-K streaming Min-Heap with average-O(n) Randomized Quickselect.

Pattern: Min-Heap Top-K
O(n log k) · O(k)
Solve
EasySliding Window

Best Time to Buy and Sell Stock

Maximize single-transaction stock profit across daily prices by contrasting pairwise brute force with a one-pass running-minimum tracker.

Pattern: One-Pass Running Minimum
O(n) · O(1)
Solve
MediumDynamic Programming

Maximum Subarray (Kadane's Algorithm)

Find the contiguous subarray with the largest integer sum. Compare quadratic prefix enumeration against Kadane's linear-time reset invariant.

Pattern: Kadane's Algorithm
O(n) · O(1)
Solve
EasyDynamic Programming

Climbing Stairs

Count distinct ways to climb n stairs taking 1 or 2 steps at a time. Progress from top-down memoization to O(1)-space Fibonacci dynamic programming.

Pattern: Fibonacci Sequence
O(n) · O(1)
Solve
MediumDynamic Programming

Coin Change

Find the minimum number of coins required to form a target amount. Compare top-down memoized search against bottom-up unbounded knapsack tabulation.

Pattern: Bottom-Up Tabulation
O(S * n) · O(S)
Solve
MediumArrays & Hashing

Merge Intervals

Merge all overlapping intervals into sorted non-overlapping ranges. Compare graph component grouping against sorting by start time + greedy scan.

Pattern: Interval Sorting
O(n log n) · O(n)
Solve

Core Patterns Reference