Skip to main content

Medium Problems (63 Problems)

Overview

The Medium difficulty tier represents the core of technical interview preparation, featuring 63 problems that bridge fundamental concepts with advanced algorithmic techniques. These problems test your ability to combine multiple patterns, optimize solutions, and handle complex edge cases.

What You’ll Master

  • Advanced Data Structures - LRU Cache, Trie, Union-Find
  • Complex Algorithms - Backtracking, graph traversal, dynamic programming
  • Optimization Techniques - Binary search on answer, sliding window, prefix sums
  • System Design Basics - Iterator patterns, streaming algorithms
  • Problem Decomposition - Breaking complex problems into manageable parts

Study Approach

For Intermediate Developers:
  1. Start with high-frequency problems (#001, #003, #016)
  2. Master core patterns (stack, tree traversal, hash table)
  3. Progress to algorithm-heavy problems (graph, DP, backtracking)
  4. Practice system design problems (#039, #048, #051)
For Interview Prep:
  • Target 30-40 minutes per problem
  • Aim for optimal solution on first attempt
  • Practice live coding with timer pressure
  • Focus on explaining trade-offs between approaches
Estimated Time Investment:
  • First-time learning: 100-130 hours
  • Interview refresh: 35-45 hours
  • Quick review: 15-20 hours

Problems by Category

Array & Hashing (9 problems)

#016 - Merge Intervals

Frequency: 77.9% | Sorting, interval manipulation

#022 - Buildings With an Ocean View

Frequency: 74.9% | Monotonic stack pattern

#023 - Custom Sort String

Frequency: 73.2% | Custom sorting, hash table

#024 - K Closest Points to Origin

Frequency: 71.4% | Heap, quickselect

#026 - Subarray Sum Equals K

Frequency: 71.4% | Prefix sum, hash table

#059 - Continuous Subarray Sum

Frequency: 47.0% | Prefix sum modulo

#062 - Group Shifted Strings

Frequency: 47.0% | String hashing

#071 - Managers with at Least 5 Direct Reports

Frequency: 40.7% | SQL-style grouping

#077 - Car Pooling

Frequency: 40.7% | Sweep line algorithm

Tree (9 problems)

#003 - Binary Tree Vertical Order Traversal

Frequency: 93.4% | BFS, hash table

#005 - Lowest Common Ancestor of a Binary Tree III

Frequency: 89.6% | Parent pointer technique

#007 - Binary Tree Right Side View

Frequency: 86.0% | Level-order traversal

#009 - Lowest Common Ancestor of a Binary Tree

Frequency: 82.9% | DFS, recursion

#011 - Nested List Weight Sum

Frequency: 81.7% | DFS on nested structures

#013 - Sum Root to Leaf Numbers

Frequency: 80.5% | Path sum variant

#066 - All Nodes Distance K in Binary Tree

Frequency: 47.0% | Tree as graph, BFS

Heap & Priority Queue (8 problems)

#006 - Kth Largest Element in an Array

Frequency: 86.9% | Quickselect, min heap

#012 - Random Pick with Weight

Frequency: 80.5% | Prefix sum, binary search

#015 - Top K Frequent Elements

Frequency: 77.9% | Bucket sort, heap

#069 - Zero Array Transformation III

Frequency: 40.7% | Range updates

#091 - Random Pick Index

Frequency: 32.0% | Reservoir sampling

Graph & DFS/BFS (8 problems)

#025 - Clone Graph

Frequency: 71.4% | DFS/BFS, hash table

#031 - Shortest Path in Binary Matrix

Frequency: 67.4% | BFS on grid

#038 - Accounts Merge

Frequency: 62.4% | Union-Find, DFS

#055 - Subsets

Frequency: 47.0% | Backtracking

#063 - Course Schedule

Frequency: 47.0% | Topological sort, cycle detection

#086 - Shortest Path in a Hidden Grid

Frequency: 32.0% | Interactive problem, BFS

Stack (5 problems)

#008 - Basic Calculator II

Frequency: 84.0% | Expression parsing

#035 - Simplify Path

Frequency: 65.0% | Stack for path normalization

#049 - Exclusive Time of Functions

Frequency: 56.0% | Stack simulation

#093 - Decode String

Frequency: 32.0% | Nested structures

#098 - Remove All Adjacent Duplicates in String II

Frequency: 32.0% | Stack with counter

Binary Search (6 problems)

#010 - Find Peak Element

Frequency: 82.9% | Binary search on unsorted

#042 - Find First and Last Position of Element in Sorted Array

Frequency: 59.4% | Binary search bounds

#074 - Cutting Ribbons

Frequency: 40.7% | Binary search on answer

#079 - Capacity To Ship Packages Within D Days

Frequency: 40.7% | Binary search optimization

#084 - Kth Smallest Element in a Sorted Matrix

Frequency: 40.7% | Binary search on value

#094 - Koko Eating Bananas

Frequency: 32.0% | Binary search on rate

Sliding Window (4 problems)

#040 - Max Consecutive Ones III

Frequency: 62.4% | Variable window size

#080 - Longest Substring Without Repeating Characters

Frequency: 40.7% | Classic sliding window

#090 - Frequency of the Most Frequent Element

Frequency: 32.0% | Window with sum constraint

Linked List (4 problems)

#032 - Copy List with Random Pointer

Frequency: 67.4% | Deep copy with hash table

#045 - Remove Nth Node From End of List

Frequency: 56.0% | Two pointer technique

#054 - Add Two Numbers

Frequency: 47.0% | Linked list arithmetic

#064 - Insert into a Sorted Circular Linked List

Frequency: 47.0% | Circular list insertion

Parentheses (2 problems)

#001 - Minimum Remove to Make Valid Parentheses

Frequency: 100.0% | Stack, string manipulation

#052 - Minimum Add to Make Parentheses Valid

Frequency: 51.9% | Greedy approach

Palindrome (2 problems)

#057 - Palindromic Substrings

Frequency: 47.0% | Expand around center

#096 - Longest Palindromic Substring

Frequency: 32.0% | Dynamic programming

Two Pointers (4 problems)

#030 - Next Permutation

Frequency: 67.4% | In-place permutation

#065 - 3Sum

Frequency: 47.0% | Two pointer with sorting

#073 - Container With Most Water

Frequency: 40.7% | Greedy two pointers

#088 - Interval List Intersections

Frequency: 32.0% | Merge technique

String (2 problems)

#046 - Diagonal Traverse

Frequency: 56.0% | Matrix traversal

#067 - String to Integer (atoi)

Frequency: 40.7% | String parsing

BST (2 problems)

#051 - Binary Search Tree Iterator

Frequency: 51.9% | Iterator design, in-order traversal

#092 - Kth Smallest Element in a BST

Frequency: 32.0% | In-order traversal application

Math & Compute (2 problems)

#021 - Pow(x, n)

Frequency: 74.9% | Fast exponentiation

#072 - Maximum Swap

Frequency: 40.7% | Greedy digit manipulation

Dynamic Programming (2 problems)

#075 - Word Break

Frequency: 40.7% | String DP

#087 - Maximum Subarray

Frequency: 32.0% | Kadane’s algorithm

Design (1 problem)

#039 - LRU Cache

Frequency: 62.4% | Hash table + doubly linked list

High Priority Problems

These medium problems appear most frequently in interviews: Top 10 Must-Know:
  1. #001 - Minimum Remove to Make Valid Parentheses (100.0%)
  2. #003 - Binary Tree Vertical Order Traversal (93.4%)
  3. #005 - Lowest Common Ancestor of a Binary Tree III (89.6%)
  4. #006 - Kth Largest Element in an Array (86.9%)
  5. #007 - Binary Tree Right Side View (86.0%)
  6. #008 - Basic Calculator II (84.0%)
  7. #009 - Lowest Common Ancestor of a Binary Tree (82.9%)
  8. #010 - Find Peak Element (82.9%)
  9. #011 - Nested List Weight Sum (81.7%)
  10. #013 - Sum Root to Leaf Numbers (80.5%)

Advanced Patterns

Pattern 1: Binary Search on Answer

Problems: #074, #079, #094 Key Insight: When looking for optimal value, binary search the answer space

Pattern 2: Union-Find for Connectivity

Problems: #038 Key Insight: Efficiently merge and query connected components

Pattern 3: Monotonic Stack

Problems: #022 Key Insight: Maintain increasing/decreasing sequence for next greater/smaller

Pattern 4: Tree to Graph Conversion

Problems: #066 Key Insight: Add parent pointers or build adjacency list for bidirectional traversal

Pattern 5: Prefix Sum with Hash Table

Problems: #026, #059 Key Insight: Store prefix sums to find subarrays in O(n)

Study Tips

Approaching Medium Problems

  1. Identify Core Patterns
    • Is it a graph problem? (connected components, shortest path)
    • Can I use binary search? (sorted, monotonic, optimization)
    • Does it need DP? (overlapping subproblems, optimal substructure)
    • Should I use sliding window? (contiguous subarray, substring)
  2. Optimize Systematically
    • Start with brute force to clarify logic
    • Identify bottlenecks
    • Apply appropriate data structure or algorithm
    • Verify correctness before coding
  3. Handle Complexity
    • Break problem into smaller subproblems
    • Use helper functions for clarity
    • Test each component independently
  4. Master Time Management
    • 5 min: Understand problem, clarify requirements
    • 10 min: Design approach, discuss trade-offs
    • 20 min: Implement solution
    • 5 min: Test and debug

Common Pitfalls

  • Overlooking edge cases in tree/graph traversal (null nodes, cycles)
  • Off-by-one errors in binary search
  • Not handling duplicates in sorting/hashing problems
  • Forgetting to update state in sliding window
  • Stack overflow in recursion (use iterative or add base cases)

Progression Path

Phase 1: High-Frequency Fundamentals (Weeks 1-2)

  • Start with top 20 highest frequency problems
  • Master core patterns: stack, tree, hash table
  • Goal: Recognize patterns instantly

Phase 2: Algorithm Mastery (Weeks 3-4)

  • Binary search variations
  • Graph algorithms (BFS, DFS, Union-Find)
  • Dynamic programming intro
  • Goal: Apply algorithms correctly

Phase 3: Complex Problem Solving (Weeks 5-6)

  • Multi-pattern problems
  • System design problems
  • Optimization challenges
  • Goal: Solve independently in 35 minutes

Ready for Hard?

You’re ready for hard problems when you can:
  • Solve most medium problems in under 35 minutes
  • Optimize from brute force independently
  • Explain multiple approaches with trade-offs
  • Debug complex logic efficiently
  • Design custom data structures (#039)

Next: Hard Problems

Challenge yourself with 16 hard-level problems that test advanced techniques

Quick Reference

Total Problems: 63 Average Frequency: 56.8% Recommended Time: 30-40 minutes per problem Total Study Time: 100-130 hours (first attempt) Key Categories:
  • Array & Hashing: 9 problems
  • Tree: 9 problems
  • Heap: 8 problems
  • Graph: 8 problems
  • Binary Search: 6 problems
  • Stack: 5 problems
  • Sliding Window: 4 problems
  • Linked List: 4 problems
  • Two Pointers: 4 problems
  • Others: 6 problems

Build docs developers (and LLMs) love