Menu

All DSA questions

DSA interview questions
#QuestionDifficultyTypeDone
1Balanced Binary Tree: Height Check with Early ExitEasycoding
2Best Time to Buy and Sell Stock: Maximum Profit From One TradeEasycoding
3Binary Search: Find a Target in a Sorted Array in O(log n)Easycoding
4Climbing Stairs: Count Ways with a Fibonacci-Style DPEasycoding
5Contains Duplicate: Detect Whether Any Value Appears TwiceEasycoding
6Convert Sorted Array to BST: Pick the Middle, Recurse on HalvesEasycoding
7Diameter of Binary Tree: Longest Path via Post-Order HeightsEasycoding
8Implement Queue using Stacks: FIFO With Two Stacks in Amortised O(1)Easycoding
9Implement Stack using Queues: LIFO Behaviour From FIFO PartsEasycoding
10Invert Binary Tree: Recursive and Iterative Mirror SolutionsEasycoding
11Kth Largest Element in a Stream: Size-k Min-HeapEasycoding
12Last Stone Weight: Simulating Smashes with a Max-HeapEasycoding
13Linked List Cycle: Floyd's Fast and Slow PointersEasycoding
14Longest Common Prefix: Shared Start of a List of StringsEasycoding
15Majority Element: Find the Value That Fills More Than Half the ArrayEasycoding
16Maximum Average Subarray I: Best Average Over a Fixed-Length WindowEasycoding
17Maximum Depth of Binary Tree: Recursive DFS, Iterative DFS and BFSEasycoding
18Merge Two Sorted Lists: Dummy Head Iteration and RecursionEasycoding
19Min Cost Climbing Stairs: Cheapest Path to the Top with 1D DPEasycoding
20Move Zeroes: Shift Zeros to the End While Keeping OrderEasycoding
21Next Greater Element I: First Larger Value to the RightEasycoding
22Number of 1 Bits: Count Set Bits in an IntegerEasycoding
23Number of Recent Calls: Count Requests in a Sliding Time WindowEasycoding
24Reverse Bits: Mirror the 32 Bits of an Unsigned IntegerEasycoding
25Reverse Linked List: Iterative and Recursive SolutionsEasycoding
26Reverse String: Reverse a Character Array in PlaceEasycoding
27Same Tree: Comparing Two Binary Trees Recursively and IterativelyEasycoding
28Single Number: Find the Value That Appears Only Once Using XOREasycoding
29Subtree of Another Tree: Brute-Force Matching and Linear SerialisationEasycoding
30Two Sum: Find Two Indices That Add Up to a TargetEasycoding
31Valid Anagram: Check Whether Two Strings Use the Same LettersEasycoding
32Valid Palindrome II: Palindrome After Deleting at Most One CharacterEasycoding
33Valid Palindrome: Check a Phrase While Ignoring Case and PunctuationEasycoding
34Valid Parentheses: Check That Every Bracket Closes in the Right OrderEasycoding
353Sum: Find All Unique Triplets That Sum to ZeroMediumcoding
36Add Two Numbers: Digit-by-Digit Addition on Linked ListsMediumcoding
37Best Time to Buy and Sell Stock with Cooldown: State-Machine DPMediumcoding
38Binary Tree Level Order Traversal: BFS with a Queue, Level by LevelMediumcoding
39Binary Tree Right Side View: Last Node of Each LevelMediumcoding
40Car Fleet: Count the Groups of Cars Arriving at a DestinationMediumcoding
41Cheapest Flights Within K Stops: Bounded Bellman-Ford for Limited HopsMediumcoding
42Clone Graph: Deep-Copy a Connected Graph with a Hash Map and BFS or DFSMediumcoding
43Coin Change II: Count Combinations That Make an AmountMediumcoding
44Coin Change: Fewest Coins with Bottom-Up DPMediumcoding
45Combination Sum II: Use Each Value Once and Avoid Duplicate AnswersMediumcoding
46Combination Sum: Reach a Target with Reusable Values via BacktrackingMediumcoding
47Construct Binary Tree from Preorder and Inorder TraversalMediumcoding
48Container With Most Water: Maximise Area Between Two LinesMediumcoding
49Copy List with Random Pointer: Hash Map and Interleaving SolutionsMediumcoding
50Count Good Nodes in Binary Tree: DFS Carrying the Path MaximumMediumcoding
51Course Schedule II: Return a Valid Course Order with Topological SortMediumcoding
52Course Schedule: Detect a Cycle in a Prerequisite Graph with Kahn's AlgorithmMediumcoding
53Daily Temperatures: Days Until a Warmer Day With a Monotonic StackMediumcoding
54Decode Ways: Count Digit-to-Letter Decodings with Prefix DPMediumcoding
55Delete Node in a BST: Leaf, One Child and Two Children CasesMediumcoding
56Design Add and Search Words: Trie Search with WildcardsMediumcoding, architecture
57Design Circular Queue: A Fixed-Capacity Ring BufferMediumcoding
58Design Twitter: News Feed with a K-Way Heap MergeMediumcoding, architecture
59Edit Distance: Levenshtein Distance with a 2D DP TableMediumcoding
60Encode and Decode Strings: Serialise a List of Strings SafelyMediumcoding
61Evaluate Reverse Polish Notation: Compute a Postfix ExpressionMediumcoding
62Find First and Last Position of a Value: Lower and Upper Bound Binary SearchMediumcoding
63Find Minimum in Rotated Sorted Array: Binary Search Against the Right EndMediumcoding
64Find the Duplicate Number: Cycle Detection on an ArrayMediumcoding
65Generate Parentheses: List Every Balanced String of n PairsMediumcoding
66Graph Valid Tree: Check Edge Count, Connectivity and Cycles with Union-FindMediumcoding
67Group Anagrams: Bucket Words That Share the Same LettersMediumcoding
68House Robber II: Non-Adjacent Maximum Sum When Houses Form a CircleMediumcoding
69House Robber: Maximum Non-Adjacent Sum with Take-or-Skip DPMediumcoding
70Implement Trie (Prefix Tree): Insert, Search and Prefix LookupMediumcoding, architecture
71Insert Interval: Add a Range to a Sorted List and Merge OverlapsMediumcoding
72Insert into a BST: Walk Down to the Empty SpotMediumcoding
73Interleaving String: Can Two Strings Merge into a Third? 2D DPMediumcoding
74K Closest Points to Origin: Bounded Max-Heap and QuickselectMediumcoding
75Koko Eating Bananas: Binary Search on the AnswerMediumcoding
76Kth Largest Element in an Array: Heap, Quickselect and CountingMediumcoding
77Kth Smallest Element in a BST: Inorder Traversal with Early StopMediumcoding
78Letter Combinations of a Phone Number: Cartesian Product by BacktrackingMediumcoding
79Longest Common Subsequence: The Classic Two-String DP TableMediumcoding
80Longest Consecutive Sequence: Longest Run of Consecutive Integers in O(n)Mediumcoding
81Longest Increasing Subsequence: O(n^2) DP and O(n log n) Patience SortingMediumcoding
82Longest Palindromic Substring: Expand Around Centres or Interval DPMediumcoding
83Longest Repeating Character Replacement: Window With At Most k ChangesMediumcoding
84Longest Substring Without Repeating Characters: Sliding WindowMediumcoding
85Lowest Common Ancestor of a Binary Tree: One Post-Order SearchMediumcoding
86Lowest Common Ancestor of a BST: Follow the Split PointMediumcoding
87LRU Cache: Hash Map Plus Doubly Linked List for O(1) OperationsMediumcoding, architecture
88Max Area of Island: Largest Connected Land Region with Flood FillMediumcoding
89Maximum Product Subarray: Track Both the Largest and Smallest ProductMediumcoding
90Maximum Subarray: Largest Sum of a Contiguous Slice with Kadane's AlgorithmMediumcoding
91Merge Intervals: Combine Every Overlapping RangeMediumcoding
92Min Cost to Connect All Points: Minimum Spanning Tree with Prim or KruskalMediumcoding
93Min Stack: A Stack That Returns Its Minimum in Constant TimeMediumcoding
94Network Delay Time: Single-Source Shortest Paths with Dijkstra's AlgorithmMediumcoding
95Non-overlapping Intervals: Fewest Removals to Eliminate OverlapsMediumcoding
96Number of Connected Components in an Undirected Graph with Union-FindMediumcoding
97Number of Islands: Count Connected Land Cells with BFS, DFS or Union-FindMediumcoding
98Pacific Atlantic Water Flow: Reverse Multi-Source BFS from Both OceansMediumcoding
99Palindrome Partitioning: Split a String into Palindromes by BacktrackingMediumcoding
100Palindromic Substrings: Count Every Palindrome by Expanding Around CentresMediumcoding
101Partition Equal Subset Sum: 0/1 Knapsack on Half the TotalMediumcoding
102Permutation in String: Does One String Contain a Rearrangement of Another?Mediumcoding
103Permutations: Every Ordering of Distinct Values with BacktrackingMediumcoding
104Product of Array Except Self: Prefix and Suffix Products Without DivisionMediumcoding
105Redundant Connection: Find the Edge That Closes a Cycle with Union-FindMediumcoding
106Remove Nth Node From End of List: One Pass with a Gap of nMediumcoding
107Reorder List: Find the Middle, Reverse, Then InterleaveMediumcoding
108Rotate Image: Turn a Square Matrix 90 Degrees Clockwise in PlaceMediumcoding
109Rotting Oranges: Minutes to Spread via Level-by-Level Multi-Source BFSMediumcoding
110Search a 2D Matrix: Binary Search over a Flattened Sorted GridMediumcoding
111Search in Rotated Sorted Array: One-Pass Binary SearchMediumcoding
112Set Matrix Zeroes: Zero Out Rows and Columns in PlaceMediumcoding
113Sort Colors: One-Pass Three-Way Partition of 0s, 1s and 2sMediumcoding
114Spiral Matrix: Read a Grid in Clockwise Spiral OrderMediumcoding
115String to Integer (atoi): Parse a Signed 32-bit Integer by HandMediumcoding
116Subarray Sum Equals K: Count Contiguous Slices With a Given SumMediumcoding
117Subsets II: Power Set Without Duplicates When Values RepeatMediumcoding
118Subsets: Generate the Power Set with Include/Exclude BacktrackingMediumcoding
119Surrounded Regions: Capture Enclosed Cells by Flood-Filling from the BorderMediumcoding
120Target Sum: Count Sign Assignments with Subset-Sum DPMediumcoding
121Task Scheduler: Cooldowns with a Max-Heap or a Counting FormulaMediumcoding
122Time Based Key-Value Store: Versioned Lookups with Binary SearchMediumcoding, architecture
123Top K Frequent Elements: Return the k Most Common ValuesMediumcoding
124Two Sum II: Find a Pair With a Target Sum in a Sorted ArrayMediumcoding
125Unique Paths: Count Grid Routes with 2D DP or a Binomial CoefficientMediumcoding
126Valid Sudoku: Check Rows, Columns and Boxes for Repeated DigitsMediumcoding
127Validate Binary Search Tree: Bounds Recursion and Inorder CheckMediumcoding
128Word Break: Can a String Be Split into Dictionary Words? Prefix DPMediumcoding
129Word Search: Trace a Word Through a Letter Grid with DFS BacktrackingMediumcoding
130Alien Dictionary: Derive a Letter Order from Sorted Words with Topological SortHardcoding
131Binary Tree Maximum Path Sum: Post-Order Gains with a Global BestHardcoding
132Burst Balloons: Interval DP by Choosing the Last Balloon to BurstHardcoding
133Find Median from Data Stream: Two Heaps Kept in BalanceHardcoding
134Largest Rectangle in Histogram: Biggest Area Under the BarsHardcoding
135Median of Two Sorted Arrays: Partition Binary Search in O(log min(m, n))Hardcoding
136Merge k Sorted Lists: Min-Heap and Divide-and-Conquer SolutionsHardcoding
137Minimum Window Substring: Shortest Slice Containing Every Required CharacterHardcoding
138N-Queens: Place Non-Attacking Queens Row by Row with BacktrackingHardcoding
139Reconstruct Itinerary: Eulerian Path with Hierholzer's AlgorithmHardcoding
140Regular Expression Matching: Dot and Star with a 2D DP TableHardcoding
141Reverse Nodes in k-Group: In-Place Group Reversal on a Linked ListHardcoding
142Serialize and Deserialize Binary Tree: Preorder with Null MarkersHardcoding
143Sliding Window Maximum: Max of Every Window With a Monotonic DequeHardcoding
144Swim in Rising Water: Minimax Path with a Modified DijkstraHardcoding
145Trapping Rain Water: Total Water Held Between Elevation BarsHardcoding
146Word Ladder: Shortest Word Transformation with BFS and Wildcard BucketsHardcoding
147Word Search II: Find Many Words in a Grid with a Trie and BacktrackingHardcoding

Ticks are saved in this browser only. No account needed.

Concept review

Continue preparing

Search
Filter by type