/Leetcode

Leetcode Practice

Primary LanguageJupyter Notebook

Problem Lists

This repo records coding problems from leetcode. All problems are organized by the corresponding category

Basic Data Structures

Arrays

Number Problem Solution Difficulty Reference Accepted Note
0011 Container With Most Water Array / Two Pointers Medium 1 2 ✔️ Top Interview 0029/150
0026 Remove Duplicates from Sorted Array Array / Two Pointers Easy 1 2 ✔️ Top Interview 0003/150
0031 Next Permutation Array Medium 1 2 ✔️
0042 Trapping Rain Water Array / Two Pointers / DP Hard 1 2 ✔️ Top Interview 0016/150
0048 Rotate Image Array / Matrix Medium 1 2 ✔️ Top Interview 0037/150
0054 Spiral Matrix Array / Matrix Medium 1 2 3 ✔️ Top Interview 0036/150
0056 Merge Intervals Array / Intervals Medium 1 2 ✔️ Top Interview 0050/150
0057 Insert Interval Array / Intervals / Similar to Leetcode_0056_Merge_Intervals Medium 1 2 ✔️ Top Interview 0051/150
0452 Minimum Number of Arrows to Burst Balloons Array / Intervals / Similar to Leetcode_0056_Merge_Intervals Medium 1 2 ✔️ Top Interview 0052/150
0228 Summary Ranges Array / Intervals Easy 1 ✔️ Top Interview 0049/150
0075 Sort Colors Array Medium 1 2 ✔️
0088 Merge Sorted Array Bubble_sort / Sorting / Two Pointers Easy 1 2 ✔️ Recap Bubble Sort / Top Interview 0001/150
0189 Rotate Array Array / Two Pointers Medium 1 2 ✔️ Top Interview 0006/150
0283 Move Zeroes Array Easy 1 ✔️
0496 Next Greater Element I Array Easy 1 ✔️
0503 Next Greater Element II Array Medium 1 ✔️
0941 Valid Mountain Array Array Easy 1 2 ✔️
1260 Shift 2D Grid Array Easy 1 ✔️
sort sort algorithm 10 sort algoritmes Easy 1 ✔️
0027 Remove Element Two Pointers Easy 1 ✔️ Top Interview 0002/150
0080 Remove Duplicates Sorted Array II Array / Two Pointers Medium 1 ✔️ Top Interview 0004/150
0238 Product of Array Except Self Array / Prefix sum Medium 1 ✔️ Top Interview 0013/150
0209 Minimum Size Subarray Sum Array / Sliding Window Medium 1 ✔️ Top Interview 0031/150
0036 Valid Sudoku Array / Matrix Medium 1 ✔️ Top Interview 0035/150
0073 Set Matrix Zeroes Array / Matrix Medium 1 Need Investigate Top Interview 0038/150
0289 Game of List Array / Matrix Medium 1 Need Investigate Top Interview 0039/150
0053 Maximum Subarray Kadane's Algorithm Medium 1 ✔️ Top Interview 0111/150
0918 Maximum Sum Circular Subarray Kadane's Algorithm Medium 1 ✔️ Top Interview 0112/150

String

Number Problem Solution Difficulty Reference Accepted Note
0006 Zigzag Conversion String Medium 1 2 ✔️ Top Interview 0022/150
0008 String to Integer (atoi) String Medium 1 ✔️
0014 Longest Common Prefix String Medium 1 ✔️ Top Interview 0023/150
0028 Implement strStr String Easy 1 ✔️ Top Interview 0024/150
0151 Reverse Words in a String String Medium 1 2 ✔️ Top Interview 0020/150
0186 Reverse Words in a String II Stack / Two Pointers Medium 1 2 ✔️
0344 Reverse String String Easy 1 ✔️
0415 Add Strings String Easy 1 ✔️
0443 String Compression String Medium 1 ✔️
0459 Repeated Substring Pattern KMP Medium 1 ✔️
0541 Reverse String II String Easy 1 2 3 ✔️
0551 Student Attendance Record I String Easy 1 ✔️ bool recap
0557 Reverse Words in a String III String Easy 1 ✔️
0809 Expressive Words String Medium 1 ✔️
0824 Goat Latin String Easy 1 ✔️
0848 Shifting Letters String Medium 1 ✔️
0937 Reorder Data in Log Files String Medium 1 ✔️
1047 Remove All Adjacent Duplicates In String String Easy 1 ✔️
0058 Length of Last Word String Easy 1 ✔️ Top Interview 0019/150
0068 Text Justification String Hard 1 Need Investigate Top Interview 0025/150
0125 Valid Palindrome String / Two Pointers Medium 1 ✔️ Top Interview 0026/150
0392 Is Subsequence String / Two Pointers Easy 1 ✔️ Top Interview 0027/150

Linked List

Number Problem Solution Difficulty Reference Accepted Note
0002 Add Two Numbers Linked List Medium 1 2 ✔️ Top Interview 0059/150
0019 Remove Nth Node From End of List fast/slow pointer Medium 1 ✔️ Top Interview 0062/150
0021 Merge Two Sorted Lists Linked List Easy 1 ✔️ Top Interview 0060/150
0023 Merge k Sorted Lists Divide&Conquer / Recursive / Binary Search Hard 1 2 3 4 5 ✔️ Top Interview 0111/150
0024 Swap Nodes in Pairs Linked List Medium 1 2 3 4 ✔️
0025 Reverse Nodes in k-Group Linked List Medium 1 ✔️ Top Interview 0066/150
0061 Rotate List fast/slow pointers Medium 1 2 ✔️ Top Interview 0064/150
0082 Remove Duplicates from Sorted List II Linked List Medium 1 ✔️ Top Interview 0063/150
0083 Remove Duplicates from Sorted List Linked List Easy 1 2 ✔️
0086 Partition List Linked List / similar to Leetcode 21. Merge Two Sorted Lists and Leetcode_0328_odd_even_linkedlist.ipynb Medium 1 2 ✔️ Top Interview 0067/150
0092 Reverse Linked List II Linked List Medium 1 ✔️ Top Interview 0061/150
0141 Linked List Cycle Linked List Easy 1 2 ✔️ Top Interview 0058/150
0142 Linked List Cycle II Linked List Medium 1 ✔️
0147 Insertion Sort List Linked List Medium 1 ✔️
0148 Sort List Divide & Conquer Medium 1 2 3 ✔️ Top Interview 0109/150
0160 Intersection of Two Linked Lists Linked List Easy 1 ✔️
0203 Remove Linked List Elements Linked List Easy 1 ✔️
0206 Reverse Linked List Linked List Easy 1 ✔️
0237 Delete Node in a Linked List Linked List Medium 1 ✔️
0328 Odd Even Linked List Linked List Medium 1 ✔️
0445 Add Two Numbers II Linked List Medium 1 ✔️
0707 Design Linked List Linked List Medium 1 ✔️
0725 Split Linked List in Parts Linked List Medium 1 ✔️
0876 Middle of the Linked List Linked List Easy 1 ✔️
0138 Copy List with Random Pointer Linked List Medium 1 ✔️ Top Interview 0065/150

Queue

Number Problem Solution Difficulty Reference Accepted Note
0225 Implement Stack using Queues Queue Easy 1 ✔️

Stack

Number Problem Solution Difficulty Reference Accepted Note
0150 Evaluate Reverse Polish Notation Stack Medium 1 ✔️ Top Interview 0056/150
0155 Min Stack Stack Medium 1 ✔️ Top Interview 0055/150
0232 Implement Queue using Stacks Stack Easy 1 2 3 4 5 ✔️
0316 Remove Duplicate Letters Stack Medium 1 ✔️
0739 Daily Temperatures Stack Medium 1 ✔️
0946 Validate Stack Sequences Stack Medium 1 ✔️
1249 Minimum Remove to Make Valid Parentheses Stack Medium 1 ✔️
0020 Valid Parentheses Stack Easy 1 2 ✔️ Top Interview 0053/150
0071 Simplify Path Stack Medium 1 ✔️ Top Interview 0054/150
0224 Basic Calculator Stack Hard 1 ✔️ Top Interview 0057/150

Advanced Data Structures

HashSet / HashTable

Number Problem Solution Difficulty Reference Accepted Note
0001 Two Sum HashMap Easy 1 2 3 ✔️ Top Interview 0045/150
0003 Longest Substring Without Repeating Characters HashMap / Sliding Window Medium 1 ✔️ Top Interview 0032/150
0015 3Sum HashMap / Two Pointers Medium 1 ✔️ Top Interview 0030/150
0018 4Sum HashMap Medium 1 ✔️
0128 Longest Consecutive Sequence HashMap Medium 1 ✔️ Top Interview 0048/150
0167 Two Sum II - Input Array Is Sorted HashMap / Two Pointers Medium 1 2 ✔️ Top Interview 0028/150
0202 Happy Number HashMap Easy 1 ✔️ Top Interview 0046/150
0205 Isomorphic Strings HashMap / Zip Easy 1 ✔️ Top Interview 0041/150
0217 Contains Duplicate HashMap Easy 1 ✔️
0242 Valid Anagram HashMap Easy 1 2 ✔️ Top Interview 0043/150 / same solution to Leetcode_0383_Ransom_Note
0347 Top K Frequent Elements HashMap Medium 1 ✔️
0349 Intersection of Two Arrays HashMap / Array Easy 1 ✔️
0383 Ransom Note HashMap / Array Easy 1 ✔️ Top Interview 0040/150
0387 First Unique Character in a String HashMap Easy 1 ✔️
0442 Find All Duplicates in an Array HashMap Medium 1 ✔️
0454 4Sum II HashMap Medium 1 ✔️
0560 Subarray Sum Equals K HashMap Medium 1 ✔️
0594 Longest Harmonious Subsequence HashMap Easy 1 2 ✔️
0705 Design HashSet HashMap Easy 1 ✔️
0953 Verifying an Alien Dictionary HashMap Easy 1 ✔️
1002 Find Common Characters HashMap Easy 1 ✔️
0169 Majority Element Array / HashMap / Divide and Conquer Easy 1 ✔️ Top Interview 0005/150
0380 Insert Delete GetRandom O(1) Array / HashMap / Math Medium 1 ✔️ Top Interview 0012/150
0013 Roman To Integer Array / HashMap / Math / String Easy 1 ✔️ Top Interview 0017/150
0012 Integer To Roman Array / HashMap / Math / String Medium 1 ✔️ Top Interview 0018/150
0076 Minimum Window Substring HashMap / Sliding Window Hard 1 ✔️ Top Interview 0033/150
0030 Substring with Concatenation of All Words HashMap / Sliding Window Hard 1 Need Investigate Top Interview 0034/150
0290 Word Pattern HashMap Easy 1 ✔️ Top Interview 0042/150
0049 Group Anagrams HashMap Medium 1 2 ✔️ Top Interview 0044/150
0219 Contains Duplicate II HashMap / Sliding Window / Add HashMap DIY method, similar to Leetcode_0217_Contains_Duplicate Easy 1 ✔️ Top Interview 0047/150

Tree

Number Problem Solution Difficulty Reference Accepted Note
0094 Binary Tree Inorder Traversal Recursive Easy 1 2 ✔️
0098 Validate Binary Search Tree Recursive Medium 1 2 ✔️ Top Interview 0087/150
0230 Kth Smallest Element in a BST BFS / BST Medium 1 2 ✔️ Top Interview 0088/150
0100 Same Tree Recursive Easy 1 ✔️ Top Interview 0069/150
0101 Symmetric Tree Recursion / Iterative using stack or que / BFS Easy 1 ✔️ Top Interview 0071/150
0102 Binary Tree Level Order Traversal Recursion / Iterative using list or que / BFS Medium 1 2 3 ✔️ Top Interview 0084/150
0103 Binary Tree Zigzag Level Order Traversal BFS Medium 1 ✔️ Top Interview 0085/150
0104 Maximum Depth of Binary Tree BFS / DFS / same as Leetcode_0102 Easy 1 ✔️ Top Interview 0068/150
0105 Construct Binary Tree from Preorder and Inorder Traversal Recursive Medium 1 ✔️ Top Interview 0072/150
0106 Construct Binary Tree from Inorder and Postorder Traversal Recursive Medium 1 ✔️ Top Interview 0073/150
0107 Binary Tree Level Order Traversal II BFS / DFS Medium 1 ✔️
0199 Binary Tree Right Side View BFS / DFS Medium 1 ✔️ Top Interview 0082/150
0637 Average of Levels in Binary Tree BFS / DFS Easy 1 ✔️ Top Interview 0083/150
0429 N-ary Tree Level Order Traversal BFS / DFS Medium 1 ✔️
0515 Find Largest Value in Each Tree Row BFS / DFS Easy 1 ✔️
0116 Populating Next Right Pointers in Each Node BFS / DFS Medium 1 2 ✔️
0117 Populating Next Right Pointers in Each Node II BFS / DFS Medium 1 ✔️ Top Interview 0074/150
0111 Minimum Depth of Binary Tree BFS / DFS Easy 1 ✔️
0114 Flatten Binary Tree to Linked List DFS Medium 1 ✔️ Top Interview 0075/150
0108 Convert Sorted Array to Binary Search Tree Recursive / Divide & conquer Easy 1 2 ✔️ Top Interview 0108/150
0110 Balanced Binary Tree Recursive Easy 1 2 ✔️
0112 Path Sum Recursive / Preorder traversal DFS Easy 1 2 ✔️ Top Interview 0076/150
0113 Path Sum II Recursive / Iterative Medium 1 ✔️
0129 Sum Root to Leaf Numbers Preorder Traversal DFS / Recursive / Same as Leetcode_0112_Path_Sum Medium 1 2 ✔️ Top Interview 0077/150
0124 Binary Tree Maximum Path Sum Recursive / Iterative Hard 1 2 Need Investigate Top Interview 0081/150
0144 Binary Tree Preorder Traversal Recursion / Iterative Easy 1 ✔️
0145 Binary Tree Postorder Traversal Recursion / Iterative Easy 1 ✔️
0199 Binary Tree Right Side View BFS Medium 1 ✔️
0222 Count Complete Tree Nodes BFS / Recursive Medium 1 ✔️ Top Interview 0078/150
0226 Invert Binary Tree DFS-Recursive / DFS-Iterative / BFS Medium 1 ✔️ Top Interview 0070/150
0235 Lowest Common Ancestor of a Binary Search Tree DFS-Recursive / DFS-Iterative / BFS Medium 1 ✔️
0236 Lowest Common Ancestor of a Binary Tree Recursive Medium 1 ✔️ Top Interview 0079/150
0173 Binary Search Tree Iterator Binary Search Tree Medium 1 Need Investigate Top Interview 0080/150
0257 Binary Tree Paths Recursive / Iterative Easy 1 ✔️
0404 Sum of Left Leaves Recursive / Iterative Easy 1 ✔️
0429 N-ary Tree Level Order Traversal Recursive / Iterative Medium 1 ✔️
0450 Delete Node in a BST Recursive Medium 1 ✔️
0501 Find Mode in Binary Search Tree DFS-Iterative Easy 1 ✔️
0513 Find Bottom Left Tree Value BFS Medium 1 ✔️
0530 Minimum Absolute Difference in BST BFS / DFS Medium 1 ✔️ Top Interview 0086/150
0538 Convert BST to Greater Tree BFS / DFS Medium 1 2 ✔️
0572 Subtree of Another Tree Recursion Medium 1 ✔️
0617 Merge Two Binary Trees Recursion Easy 1 ✔️
0637 Average of Levels in Binary Tree BFS Easy 1 ✔️
0654 Maximum Binary Tree Recursion Medium 1 2 ✔️
0669 Trim a Binary Search Tree Recursion Medium 1 2 ✔️
0700 Search in a Binary Search Tree Recursion / Iterative Easy 1 ✔️
0701 Insert into a Binary Search Tree Recursion / Iterative Medium 1 ✔️

Heap

Number Problem Solution Difficulty Reference Accepted Note
0295 Find Median from Data Stream Heap Hard 1 2 ✔️ Recap Heap can see Leetcode_1584
0973 K Closest Points to Origin Heap Medium 1 ✔️ Recap Heap
0703 Kth Largest Element in a Stream Heap Medium 1 ✔️
0215 Kth Largest Element in an Array Heap / Quick Select Medium 1 ✔️
0692 Top K Frequent Words Heap / Dict Medium 1 2 Need Investigate

Graph (Breadth-FS)

Number Problem Solution Difficulty Reference Accepted Note
0127 Word Ladder HashMap Easy 1 ✔️
0200 Number of Islands BFS / DFS Medium 1 2 ✔️ Top Interview 0089/150
0207 Course Schedule BFS / Iterative Medium 1 ✔️ Top Interview 0093/150
0210 Course Schedule II BFS / Iterative Medium 1 ✔️ Top Interview 0094/150
0310 Minimum Height Trees Topological Easy 1 2 3
0463 Island Perimeter DFS Easy 1 ✔️
1466 Reorder Routes to Make All Paths Lead to the City Zero BFS Medium 1 ✔️
0286 Walls and Gates Multi-Source BFS Medium 1 ✔️
0787 Cheapest Flights Within K Stops Ballman-Ford Algorithm Medium 1 ✔️
0994 Rotting Oranges BFS Medium 1 ✔️
0752 Open the Lock BFS Medium 1 Need Investigate
0934 Shortest Bridge BFS / DFS Medium 1 Need Investigate
0909 Snakes and Ladders BFS Medium 1 ✔️ Top Interview 0095/150
0433 Minimum Genetic Mutation BFS / DFS / same idea as Leetcode_0127 Medium 1 ✔️ Top Interview 0096/150
0127 Word Ladder BFS Hard 1 ✔️ Top Interview 0097/150

Graph (Best-FS)

Number Problem Solution Difficulty Reference Accepted Note

Graph (DFS)

Number Problem Solution Difficulty Reference Accepted Note
0133 Clone Graph DFS Medium 1 2 Need Investiage Top Interview 0091/150
0399 Evaluate Division DFS Medium 1 ✔️ Top Interview 0092/150
0417 Pacific Atlantic Water Flow DFS Medium 1 ✔️
0743 Network Delay Time Djikstra Medium 1 2 ✔️
0261 Graph Valid Tree DFS Medium 1 ✔️
0212 Word Search II DFS / Trie / Backtracking Hard 1 Top Interview 0099/150
1584 Min Cost to Connect All Points Minimum Cost Spanning Tree / Prim's Algorithm Medium 1 ✔️ Recap heapq & Learn Prim's Algorithm
1905 Count Sub Islands DFS Medium 1 ✔️ Similar as Leetcode_0200_Number_of_Islands
0778 Swim in Rising Water Dijkstra's Algorithm Hard 1 ✔️
0130 Surrounded Regions Reverse thinking / Graph DFS Medium 1 ✔️ Top Interview 0090/150
0695 Max Area of Island DFS Medium 1 ✔️ Similar to Leetcode_0200_Number_of_Islands.ipynb
0332 Reconstruct Itinerary DFS Hard 1 ✔️
0329 Longest Increasing Path in a Matrix DFS Hard 1 ✔️
0802 Find Eventual Safe States DFS Medium 1 Need Investigate

Basic Algorithms

Binary Search

Number Problem Solution Difficulty Reference Accepted Note

Breadth-First Search

Number Problem Solution Difficulty Reference Accepted Note

Best-First Search

Number Problem Solution Difficulty Reference Accepted Note

Depth-First Search

Number Problem Solution Difficulty Reference Accepted Note

Backtracking

Number Problem Solution Difficulty Reference Accepted Note
0079 Word Search DFS Medium 1 ✔️ Top Interview 0107/150
0017 Letter Combinations of a Phone Number DFS Medium 1 ✔️ Top Interview 0101/150
0077 Combinations DFS Medium 1 ✔️ Top Interview 0102/150
0046 Permutations DFS Medium 1 ✔️ Top Interview 0103/150
0039 Combination Sum DFS Medium 1 ✔️ Top Interview 0104/150
0052 N-Queens II DFS Hard 1 ✔️ Top Interview 0105/150
0022 Generate Parentheses DFS Medium 1 ✔️ Top Interview 0106/150

Divide & Conquer

Number Problem Solution Difficulty Reference Accepted Note
0148 Sort List Divide & Conquer Medium 1 2 3 ✔️ Top Interview 0109/150
0108 Convert Sorted Array to Binary Search Tree Recursive / Divide & conquer / Binary Search Easy 1 2 ✔️ Top Interview 0108/150
0427 Construct Quad Tree Recursive / Divide & conquer / Binary Search Medium 1 ✔️ Top Interview 0110/150

Dynamic Programming 1D

Number Problem Solution Difficulty Reference Accepted Note
0121 Best Time to Buy and Sell Stock Array / DP / Sliding Window Easy 1 ✔️ Top Interview 0007/150 / Understand for-loop and while-loop
0122 Best Time to Buy and Sell Stock II Array / DP / Sliding Window / Greedy Medium 1 ✔️ Top Interview 0008/150 / Understand DP
0055 Jump Game Array / DP / Greedy Medium 1 ✔️ Top Interview 0009/150 / Understand DP & Greedy
0055 Jump Game II Array / DP / Greedy Medium 1 ✔️ Top Interview 0010/150 / Understand DP & Greedy
0274 H-Index Array / Soring / binary_Search Medium 1 ✔️ Top Interview 0011/150
0134 Gas_Station Greedy Medium 1 ✔️ Top Interview 0014/150
0135 Candy Greedy / Two Passes of Linear scans Medium 1 ✔️ Top Interview 0015/150

Dynamic Programming 1D (Multiple States)

Number Problem Solution Difficulty Reference Accepted Note

Dynamic Programming 2D (2D Input)

Number Problem Solution Difficulty Reference Accepted Note

Dynamic Programming 2D (Two 1D Inputs)

Number Problem Solution Difficulty Reference Accepted Note
0072 Edit Distance DP Hard 1 2 ✔️ Bottom-up DP

Dynamic Programming 2D (1D Input)

Number Problem Solution Difficulty Reference Accepted Note

Dynamic Programming 2D (1D Input + K)

Number Problem Solution Difficulty Reference Accepted Note

Dynamic Programming (Knapsack)

Number Problem Solution Difficulty Reference Accepted Note

Dynamic Programming (Others)

Number Problem Solution Difficulty Reference Accepted Note

Math

Number Problem Solution Difficulty Reference Accepted Note

Advanced Algorithms

Trie

Number Problem Solution Difficulty Reference Accepted Note
0208 Implement Trie Prefix Tree Trie / Prefix Tree Medium 1 ✔️ Top Interview 0098/150
0211 Design Add and Search Words Data Structure Trie / Prefix Tree Medium 1 ✔️ Top Interview 0100/150

Union Find

Number Problem Solution Difficulty Reference Accepted Note
0684 Redundant Connection Graph Problems - Union Find Medium 1 Need Investigate
0323 Number of Connected Components in an Undirected Graph Graph Problems - Union Find Medium 1 Need Investigate

Topological Sort

Number Problem Solution Difficulty Reference Accepted Note
0269 Alien Dictionary - Topological Sort Graph Problems - Graph Hard 1 Need Investigate

Boyer-Moore Voting Algorithm

Number Problem Solution Difficulty Reference Accepted Note

Complex Problems

HashTable + Doubly Linked List

Number Problem Solution Difficulty Reference Accepted Note