Coding Interview Questions
Simulated interview flows for classic problems, covering everything from the initial prompt to the final, optimized code.
Arrays & Hashing
Contains Duplicate
Arrays & Hashing
Determine if an array of integers contains any duplicate values.
Valid Anagram
Arrays & Hashing
Check if two strings are anagrams of each other.
Two Sum
Arrays & Hashing
Find indices of two numbers in an array that add up to a specific target.
Group Anagrams
Arrays & Hashing
Group an array of strings by their anagrams.
Top K Frequent Elements
Arrays & Hashing
Find the k most frequent elements in an array.
Encode and Decode Strings
Arrays & Hashing
Design an algorithm to encode a list of strings to a single string and decode it back.
Product of Array Except Self
Arrays & Hashing
Compute an array where each element is the product of all other elements.
Longest Consecutive Sequence
Arrays & Hashing
Find the length of the longest sequence of consecutive elements in an unsorted array.
Two Pointers
Valid Palindrome
Two Pointers
Check if a string is a palindrome, ignoring case and non-alphanumeric characters.
3Sum
Two Pointers
Find all unique triplets in the array which give the sum of zero.
Container With Most Water
Two Pointers
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Sliding Window
Best Time to Buy and Sell Stock
Sliding Window
Find the maximum profit that can be achieved by buying and selling a stock once.
Longest Substring Without Repeating Characters
Sliding Window
Find the length of the longest substring without repeating characters.
Longest Repeating Character Replacement
Sliding Window
Find the longest substring with the same letter after at most k replacements.
Minimum Window Substring
Sliding Window
Find the smallest substring that contains all characters of another string.
Binary Search
Linked List
Reverse Linked List
Linked List
Reverse a singly linked list.
Merge Two Sorted Lists
Linked List
Merge two sorted linked lists into one sorted list.
Linked List Cycle
Linked List
Determine if a linked list has a cycle in it.
Reorder List
Linked List
Reorder a linked list to be L0→Ln→L1→Ln-1→L2→Ln-2→…
Remove Nth Node From End of List
Linked List
Remove the nth node from the end of a linked list.
Merge K Sorted Lists
Linked List
Merge k sorted linked lists into one sorted linked list.
Trees
Invert Binary Tree
Trees
Invert a binary tree by swapping its left and right children.
Maximum Depth of Binary Tree
Trees
Find the maximum depth or height of a binary tree.
Same Tree
Trees
Check if two binary trees are structurally identical and have the same node values.
Subtree of Another Tree
Trees
Check if a binary tree has another tree as its subtree.
LCA of a BST
Trees
Find the lowest common ancestor (LCA) of two given nodes in a Binary Search Tree.
Binary Tree Level Order Traversal
Trees
Traverse a binary tree level by level.
Validate Binary Search Tree
Trees
Determine if a binary tree is a valid binary search tree (BST).
Kth Smallest Element in a BST
Trees
Find the kth smallest element in a Binary Search Tree.
Construct Binary Tree from Preorder and Inorder Traversal
Trees
Reconstruct a binary tree from its preorder and inorder traversal sequences.
Binary Tree Maximum Path Sum
Trees
Find the maximum path sum in a binary tree. The path may start and end at any node.
Serialize and Deserialize Binary Tree
Trees
Design an algorithm to serialize a binary tree to a string and deserialize it back.
Heap / Priority Queue
Backtracking
Tries
Implement Trie (Prefix Tree)
Tries
Implement a trie data structure with insert, search, and startsWith methods.
Design Add and Search Words Data Structure
Tries
Design a data structure that supports adding words and searching with wildcards.
Word Search II
Tries
Find all words from a dictionary that exist in a grid of characters.
Graphs
Number of Islands
Graphs
Count the number of islands in a 2D grid.
Clone Graph
Graphs
Make a deep copy of an undirected graph.
Pacific Atlantic Water Flow
Graphs
Find all cells in a grid from which water can flow to both oceans.
Course Schedule
Graphs
Determine if you can finish all courses given a set of prerequisites.