Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

David's LeetCode Practice Build Status codecov

Testing

  • local dependencies
    • pytest
    • pytest-cov
    • coverage

Correctness (based on pytest)

Test all the units (in the main directory):

py.test -v

Code Coverage

pytest --cov-report term --cov Python3/

if successful you should see a new .coverage file

coverage report

Python3 Progress

Python 3.8

Symbols

  • Difficulty:
    • Harder: ▲
    • Same: -
    • Easier: ▼
  • Important: *
  • Good: 👍

Abbreviation

  • Algorithm
    • DP - Dynamic Programming
    • DC - Divide and Conquer
  • Data Structure
    • HT - Hash Table
    • BST - Binary Search Tree
    • PQ - Priority Queue (usually Heap)
  • Others
    • BM - Bit Manipulation

Naive means the first thought of mine (usually a little better than Brute-Force, but may need to be optimized.)

LeetCode Patterns

  • Leetcode Patterns – Medium
    • Leetcode Pattern 0 - Iterative traversals on Trees
    • Leetcode Pattern 1 - DFS + BFS
    • Leetcode Pattern 2 - Sliding Windows for Strings
    • Leetcode Pattern 3 - Backtracking
    • Leetcode Pattern 4 - Meta Stuff

Remark

  • Catagory
    • Catagory1, Catagory2, ...
    • Usually record in (input data) Data Structure. (The Algorithm (and additional/special Data Structrue) strategy will be noted in the Method field)
    • Code will be put in the main catagory folder (i.e. the first one).
    • Some catagory may be the Related Topic tags marked by LeetCode.
    • (Add Pattern 0~4 in brackets)
    • TODO: Most of the categories need to be updated. (The date before 2018/9/22)
Number Difficulty Problem Date Category Method-TimeComplexity Remark TODO
👍 001 Easy Two Sum 2018/3/12 Array, HT Naive-O(nlogn), HT-O(n), Sorted HT-O(n) Note -
002 Medium Add Two Numbers 2018/3/12 Linked List Naive-O(n) Note Make a shorter version
👍 003 Medium * Longest Substring Without Repeating Characters 2018/9/24 String, HT Sliding Window, Sliding Window Optimized Note -
👍 005 Medium * Longest Palindromic Substring 2019/2/28 String, DP Naive-O(n³), DP-O(n²), Expand Around Center-O(n²) Note -
006 Medium ZigZag Conversion 2018/3/22 Array Naive-O(n) Note -
007 Easy Reverse Integer 2018/3/22 Array Naive-O(n) Note -
008 Medium String to Integer (atoi) 2018/9/30 String Naive-O(n) Note -
009 Easy Palindrome Number 2018/3/22 Array Naive-O(n), Without using string-O(n) Note -
010 Hard * Regular Expression Matching 2018/10/13 String DC-O((m+n) x 2ⁿ), Top-Down DP-O(mn), Bottom-Up DP-O(mn) Note -
011 Medium Container With Most Water 2018/9/22 Array Naive-O(n²), TwoPointer-O(n) Note -
012 Medium Integer to Roman TODO String Naive-O(n) Note -
013 Easy Roman to Integer 2018/9/29 String Naive-O(n) Note -
014 Easy Longest Common Prefix 2018/9/16 Array Naive-O(n*len) Note -
👍 015 Medium ▲ 3Sum 2018/10/13 Array TwoPointer-O(n²), Naive-O(n²), TwoPointer2-O(n²), BinarySearch-O(n²) Note do it again
016 Medium 3Sum Closest 2018/10/13 Array TwoPointer-O(n²) Note -
017 Medium Letter Combinations of a Phone Number 2019/3/1 String Backtracking-O(n!) Note -
👍 018 Medium ▲ 4Sum 2019/3/2 Array, HT GeneralizedTwoPointer-O(n³) Note -
019 Medium * Remove Nth Node From End of List 2019/3/3 Linked List HT-O(n), TwoPointer-O(n) Note, Sina Interview do it again
👍 020 Easy Valid Parentheses 2018/9/15 String, Stack Naive-O(n), Stack-O(n), HashTable-O(n) Note, Learn: Queue & Stack -
021 Easy Merge Two Sorted Lists 2018/6/27 Linked List Better-O(n) Note -
023 Hard Merge k Sorted Lists 2018/6/26 Linked List Naive-O(kn), DC-O(nlogk) Note Compare K each time, Heap, attrgetter
👍 022 Medium * Generate Parentheses 2019/3/6 String Backtracking-O(n!), Naive-O(n!) Note -
024 Medium Swap Nodes in Pairs 2018/5/31 Linked List Naive-O(n), Recursive-O(n) Note -
026 Easy Remove Duplicates from Sorted Array 2018/6/14 Array Naive-O(n), Better-O(n) Note -
027 Easy Remove Element 2019/7/2 Array Naive-O(n), Naive2-O(n) Note -
028 Easy Implement strStr() 2019/7/2 String Naive-O(n) Note -
031 Medium ▲ Next Permutation 2019/3/4 Array SinglePass-O(n) Note Permutation with duplicates
👍 033 Medium * Search in Rotated Sorted Array 2019/3/5 Array BinarySearch-O(log(n)), BinarySearch2-O(log(n)) Note -
👍 035 Easy Search Insert Position 2019/7/3 Array BinarySearch-O(log(n)), Naive-O(logn) Note -
036 Medium ▼ Valid Sudoku 2018/6/21 Array HT-O(n) Note -
037 Hard Sudoku Solver TODO Array Note -
038 Easy Count and Say 2019/9/30 String Naive-O(n) Note -
039 Medium Combination Sum 2019/3/7 Array Backtracking-O(n!), Naive-O(n!) Note improve time complexity by not use sort
👍 042 Hard * Trapping Rain Water TODO Array -
👍 044 Hard Wildcard Matching TODO String Note DP, NFA
👍 045 Medium * Jump Game II 2020/10/14 Array DP-O(n^2), Greedy-O(n^2), BFS-O(n^2) do it again with all solutions
👍 046 Medium * Permutations 2018/5/31 Array Backtracking-O(n!), Recursive-O(n!), DFS Based-O(n!) Note -
👍 048 Medium * Rotate Image 2019/12/2 Array Naive-O(n) Note -
👍 049 Medium * Group Anagrams 2019/12/3 String, HT Naive-O(nk), Sorting-O(nklogk), Counter-O(nk) Note testcase
👍 050 Medium * Pow(x, n) 2020/7/16 Math Naive-O(n), Recursive-O(logn), Recursive 2-O(logn), Bit Manipulation-O(logn) -
👍 051 Hard * N-Queens 2020/7/25 Array Naive-O(n^2) testcase, TODO: another slash way in isValid
052 Hard N-Queens II 2020/7/25 Array Naive-O(n^2) testcase, TODO: another slash way in isValid
👍 053 Easy ▲ Maximum Subarray 2018/6/12 Array, DP, DC BruteForce-O(n³), DP-O(n), DC-O(nlogn) Note Do it again
👍 055 Medium * Jump Game 2020/4/26 Array Backtracking-O(2^n), DPTopDown-O(n^2), DPBottomUp-O(n^2), Greedy-O(n), Greedy2-O(n) Note, Good DP walk through -
056 Medium * Merge Intervals 2020/2/21 Array Sorting-O(nlogn), Naive-O(nlogn), Better-O(nlogn), Graph-O(n^2), Tree(Stream)-O(n^2) Note Improve performance
058 Easy Length of Last Word 2019/9/30 String Not even worth to do - -
👍 060 Medium * Permutation Sequence 2020/6/20 String Naive-O(n!), Backtracking-O(n!), Math-O(n) do it again (math one)
061 Medium * Rotate List 2020/10/7 Linked List Naive-O(n) do it again with better way
👍 062 Medium Unique Paths 2020/6/29 Array Naive-O(m+n), DP-O(mn) -
👍 064 Medium * Minimum Path Sum 2020/4/19 Array Naive-O(mn), NoAdditionalSpace-O(mn) testcase
066 Easy Plus One 2019/10/19 Array Naive-O(n), FullAdder - -
067 Easy Add Binary 2019/10/22 String Adder-O(n), Iterative-O(n) - -
069 Easy Sqrt(x) 2019/10/22 Search Naive-O(n), BinarySearch-O(logn), BinarySearch2-O(logn), BinarySearch3-O(logn) - -
070 Easy Climbing Stairs 2018/6/13 DP DP-O(n), Recursive-O(n), Naive-O(n) Note -
071 Medium Simplify Path 2019/12/17 String Stack-O(n) Note -
👍 072 Hard Edit Distance 2019/10/30 String DP-O(mn), Recursive-O(mⁿ) Note -
👍 075 Medium Sort Colors 2020/6/11 Array CountingSort-O(n), DutchNationalFlagProblem-O(n) Note testcase, do this again
👍 078 Medium Subsets 2018/6/27 BM Binary-O(2ⁿ), DFSBased-O(2ⁿ), Backtracking-O(2ⁿ), Naive-O(2ⁿ) Note -
👍 079 Medium * Word Search 2020/6/30 Array Naive-O(nlogn), DFS-O(mn4^s), DFS 2-O(mn4^s) do it again
083 Easy Remove Duplicates from Sorted List 2019/10/22 Linked List Naive-O(n) - -
085 Hard Maximal Rectangle TODO Array Note -
👍 086 Medium * Partition List 2020/10/18 Linked List TwoPointer-O(n) Naive-O(n) Fix WA, do it again
088 Easy Merge Sorted Array 2019/11/18 Array Naive-O(n) -
091 Medium * Decode Ways 2020/9/28 Array Naive-O(n), Note TODO: Top-down DP, Bottom-up DP, Constant Space DP
👍 092 Medium * Reverse Linked List II 2020/9/20 Linked List Naive-O(n), OnePass-O(n) testcase, OnePass
093 Medium Restore IP Addresses 2019/12/16 Array Backtracking-O(nlogn) Note -
094 Medium Binary Tree Inorder Traversal 2018/5/29 Binary Tree Recursive-O(n), Iterative-O(n) Note -
👍 096 Medium * Unique Binary Search Tree 2020/6/24 Binary Tree Naive-O(n) testcase, do it again
098 Medium ▼ Validate Binary Search Tree 2018/6/25 BST Inorder-O(n), DFS-O(n) Note -
👍 100 Easy Same Tree 2019/11/20 Binary Tree Recursive-O(n), Naive-O(n) Note -
👍 101 Easy ▲ Symmetric Tree 2018/6/8 Binary Tree Recursive-O(n), Iterative-O(n) Note -
102 Medium * Binary Tree Level Order Traversal 2018/6/7 Binary Tree BFS-O(n) Note -
👍 103 Medium * Binary Tree Zigzag Level Order Traversal 2020/7/22 Binary Tree Naive-O(n), Without Reverse-O(n) -
👍 104 Easy Maximum Depth of Binary Tree 2018/6/8 Binary Tree Top-Down-O(n), Bottom-up-O(n), Top-Down2-O(n) Note -
105 Medium * Construct Binary Tree from Preorder and Inorder Traversal 2018/6/9 Binary Tree DC-O(n) Note -
106 Medium * Construct Binary Tree from Inorder and Postorder Traversal 2018/6/8 Binary Tree DC-O(n), Naive-O(n) Note use index instead of copy array
107 Easy Binary Tree Level Order Traversal II 2019/12/30 Binary Tree Naive-O(n), Naive 2-O(n) - -
108 Easy Convert Sorted Array to Binary Search Tree 2019/11/13 BST Recursive-O(n) Note Test case
109 Medium Convert Sorted List to Binary Search Tree 2019/11/13 BST TwoPointerRecursive-O(nlogn) Note Inorder Simulation, Test case
👍 110 Easy ▲ Balanced Binary Tree 2019/12/30 Binary Tree Naive-O(n), Better Recursive-O(n), Postorder Iterative-O(n) Note do it again
111 Easy Minimum Depth of Binary Tree 2019/11/1 Binary Tree BFS-O(n) -
👍 112 Easy Path Sum 2018/6/8 Binary Tree Naive-O(n) Note Can be imporved
👍 113 Medium Path Sum II 2019/12/23 Binary Tree Naive-O(n) Note -
👍 114 Medium Flatten Binary Tree to Linked List 2019/12/31 Binary Tree Naive-O(n) Note more elegant way
116 Medium Populating Next Right Pointers in Each Node 2019/12/24 Binary Tree Naive-O(n), DFS-O(n) Note Test
117 Medium * Populating Next Right Pointers in Each Node II 2019/12/24 Binary Tree DFS-O(n) Note Test
118 Easy Pascal's Triangle 2019/12/28 Array Naive-O(n) Note Faster approach (memory, recursive, iterative)
120 Medium * Triangle 2019/12/25 Array Naive-O(n) Note less space DP
121 Easy Best Time to Buy and Sell Stock 2018/6/13 Array Not so DP-O(n), Naive-O(n), DP-O(n) Note -
👍 122 Easy Best Time to Buy and Sell Stock II 2018/6/14 Array Greedy-O(n), Tricky-O(n), Max-O(n) Note -
👍 124 Hard Binary Tree Maximum Path Sum 2020/4/29 BinaryTree Recursive-O(nlogn) - testcase, do this again
125 Easy Valid Palindrome 2020/1/2 String Naive-O(n), Naive2 (Two Pointer)-O(n) - -
127 Medium * Word Ladder 2019/12/25 String BFS-O(n) Note Bidirectional BFS
👍 128 Hard ▼ Longest Consecutive Sequence 2019/11/14 Array Naive-O(n²), HT-O(n) Note -
👍 129 Medium * Sum Root to Leaf Numbers 2020/6/26 Binary Tree Naive-O(nlogn), DFS-O(n) -
👍 130 Medium Surrounded Regions 2020/3/25 Array Naive-O(mn), Boarders-O(mn) Note
133 Medium Clone Graph 2020/1/16 Graph Recursive-O(n), DFS-O(n) Note, Learn: Queue & Stack Do it again
👍 136 Easy Single Number 2019/12/18 Array HT-O(n), Set-O(n), BM-O(n) Note -
👍 137 Medium * Single Number II 2020/6/22 Array Naive-O(n), BitManipulation-O(n), BitManipulation 2-O(n), Math-O(n) testcase
👍 138 Medium * Product of Array Except Self 2020/3/18 Array ProductList-O(n), ProductList2-O(n), SingleProductList-O(n) Note testcase
👍 139 Medium Word Break 2020/1/14 String Recursive-O(2ⁿ), DP-O(n²) Note -
👍 140 Hard Word Break II 2020/7/30 String Naive-O(n^2) -
141 Easy * Linked List Cycle 2019/12/31 Linked List Naive-O(n), TwoPointer-O(n) Note, Microsoft testcase
👍 142 Medium * Linked List Cycle II 2020/6/25 Linked List TwoPointer-O(n) do it again
143 Medium Reorder List 2020/3/25 Linked List Naive-O(n), Improved-O(n) testcase
144 Medium Binary Tree Preorder Traversal 2018/5/29 Binary Tree Recursive-O(n), Iterative-O(n) Note -
145 Hard ▼ Binary Tree Postorder Traversal 2018/6/2 Binary Tree Recursive-O(n), Iterative-O(n) Note -
👍 146 Hard * ▼ LRU Cache 2018/6/25 Design Naive, OrderedDict, DoubleLinkedList Note
147 Medium Insertion Sort List 2020/1/14 Linked List Naive-O(n²) Note Do it again with other style
👍 148 Medium * Sort List 2020/5/11 Linked List MergeSort-O(nlogn) Do it again, InsertionSort-O(n^2), testcase
👍 150 Medium Evaluate Reverse Polish Notation 2020/2/10 Array Stack-O(n) Note, Learn: Queue & Stack -
151 Medium * Reverse Words in a String 2019/10/22 String Pythonic-O(n), Trick-O(n), Naive-O(n), C Style-O(n) Note, Microsoft Intern Interview -
👍 153 Medium * Find Minimum in Rotated Sorted Array 2020/7/25 Array Naive-O(logn), Simpler-O(logn) -
👍 154 Hard * Find Minimum in Rotated Sorted Array II 2020/7/25 Array Naive-O(logn), YetAnother-O(logn) -
155 Easy Min Stack 2018/6/28 Design Naive, Improve Note, Learn: Queue & Stack Naive?!
167 Easy Two Sum II - Input array is sorted 2019/9/18 Array TwoPointer-O(n) Note -
169 Easy Majority Element 2020/5/6 Array Naive-O(n), Counter-O(n), Sorting-O(nlogn), Boyer-Moore Voting-O(n) -
👍 174 Hard * Dungeon Game 2020/6/21 Array DP-O(mn) do it again, TODO: bottom-up dp with binary search
189 Easy Rotate Array 2018/6/14 Array NaiveInPlace-O(k), ExtraArray-O(n), Simplest-O(n) Note Cyclic Replacements / Reverse
190 Easy Reverse Bits 2020/7/12 Bit Manipulation Naive-O(n), String-O(n) testcase
198 Easy House Robber 2018/6/14 DP DP-O(n) Note Can improve space complexity
👍 200 Medium * Number of Islands 2019/7/5 Search BFS-O(n²), DFS-O(n²) Note, Learn: Queue & Stack, Dropbox OA try Union, do this again
👍 201 Medium Bitwise AND of Numbers Range 2020/4/23 BitManipulation Naive-O(n), Improve-O(n)
202 Easy Happy Number 2020/4/2 Math Naive-O(n) testcase
203 Easy Remove Linked List Elements 2020/3/18 Linked List Dummy Node-O(n), Single Pointer-O(n) testcase
👍 204 Easy * Count Primes TODO Math -
206 Easy Reverse Linked List 2018/6/26 Linked List Iterative-O(n), Recursive-O(n) Note -
👍 207 Medium * Course Schedule 2020/7/18 Array CycleDetect-O(n), TopologicalSort-O(n), DFS-O(n) - do it again
👍 208 Medium * Implement Trie (Prefix Tree) 2018/6/24 Design Naive, Trie (using Hashmap), Trie (using Array) Note testcase
👍 210 Medium * Course Schedule II 2020/7/18 Array TopologicalSort-O(n) - do it again, testcase
👍 211 Medium * Add and Search Word - Data structure design 2020/6/30 Design Naive-O(n), RegEx-O(n), Tire-O(n) Note, Tire 2-O(n) do it again
👍 212 Hard * Word Search II 2020/6/30 Array Tire-O(n) - do it again, testcase
👍 215 Medium * Kth Largest Element in an Array 2019/9/18 Array QuickSort-O(nlogn), SelectionSortLike-O(n) Note do it again, min-heap, quick select
👍 216 Medium * Combination Sum III TODO Math Naive-O(n) DP
👍 221 Medium * Maximal Square 2020/4/27 Array Naive-O(k x (mn)^2), BruteForce-O((mn)^2), DP-O(mn), Better DP-O(mn) Note -
👍 221 Medium * Count Complete Tree Nodes 2020/6/23 Binary Tree Naive-O(n), BinarySearch-O(n) testcase
225 Easy Implement Stack using Queues 2018/6/24 Design Two Queue Note, Learn: Queue & Stack -
👍 226 Easy * Invert Binary Tree 2020/6/1 Binary Tree Naive Note -
👍 230 Medium * Kth Smallest Element in a BST 2020/5/20 Binary Tree Naive-O(n), Iterative-O(n) Note testcase
231 Easy * Power of Two 2020/6/8 Math Naive-O(n), String-O(n), BitManipulation-O(n) do it again
232 Easy Implement Queue using Stacks 2018/6/24 Design Two Stack Note, Learn: Queue & Stack -
236 Medium Lowest Common Ancestor of a Binary Tree 2018/6/10 Binary Tree Naive-O(n), Naive 2-O(n), Elegant-O(n) Note testcase
237 Easy Delete Node in a Linked List 2020/3/18 Linked List Naive-O(1) (not worth to do) testcase..
👍 239 Hard * Sliding Window Maximum TODO Array Naive-O(n^2), Monotonic Queue-O(n) Dropbox OA -
252 Easy * Meeting Rooms (premium) 2020/2/20 Array Sorting-O(nlogn) Note, Facebook -
👍 253 Medium * Meeting Rooms II (premium) 2020/3/14 Array Sorting-O(nlogn) Note, Facebook -
👍 257 Easy ▲ Binary Tree Paths 2018/6/11 Binary Tree Iterative-O(n), Recursive-O(n) Note, Learn: Queue & Stack -
258 Easy Add Digits 2020/3/18 Array Naive-O(n), Iterative-O(n), NoLoop-O(1) Note, Microsoft, not good -
👍 260 Medium * Single Number III 2020/6/22 Array Naive-O(n), BitManipulation-O(n)
263 Easy Ugly Number 2020/7/4 Array Naive-O(n)
👍 264 Medium * Ugly Number II 2020/7/4 Array PriorityQueue-O(n), DP-O(n) Note, Microsoft Intern Interview do it again
278 Easy First Bad Version 2020/5/1 Iteractive Naive-O(logn) testcase
274 Medium H-Index 2020/6/18 Array CumulativeSum-O(n) sorting-based solution see 275 testcase, do it again
275 Medium H-Index II 2020/6/18 Array Linear-O(n), BinarySearch-O(n) testcase, do it again
👍 287 Medium Find the Duplicate Number 2020/6/25 Array Naive-O(n^2), TwoPointer-O(n) do it again, testcase
👍 279 Medium * Perfect Squares 2019/8/22 Search BFS-O(n), Recursive-O(n!), Top-Down DP-O(n), Linear Check-O(n * sqrt(n)), Bottom-Up DP-O(n), Math-O(sqrt(n)) Note do it again
283 Easy Move Zeroes 2020/4/4 Array Naive-O(n), TwoPointer-O(n) - testcase
297 Hard Serialize and Deserialize Binary Tree 2019/11/14 Binary Tree Naive-O(n), Naive2-O(n) Note do it again with pre-order + queue
👍 300 Medium Longest Increasing Subsequence 2019/11/11 Array BruteForce-O(2ⁿ), MemoryRecursive-O(n²), DP-O(n²), BinarySearch-O(nlogn) Note -
👍 309 Medium * Best Time to Buy and Sell Stock with Cooldown 2020/7/29 Array StateMachine-O(n), DP-O(n) -
👍 316 Medium * Remove Duplicate Letters 2020/10/11 String Greedy-O(n) do it again
👍 322 Medium * Coin Change 2020/10/5 Array Naive-O(n), DP-O(n * a) testcase, do it again
👍 328 Medium * Odd Even Linked List 2020/5/16 Linked List Naive-O(n) testcase, do it again
👍 330 Hard Patching Array 2020/8/17 Array Naive-O(n^2), Trick-O(n) -
👍 332 Medium * Reconstruct Itinerary 2020/6/28 Array Naive-O(n), EulerianPath-O(ElogE), DFS-O(nlogn) do it again
342 Easy Power of Four 2020/8/4 Math Naive-O(n), Math-O(n) testcase
344 Easy Reverse String 2020/6/4 String Naive-O(n), Recursive-O(n) Note testcase
👍 347 Medium * Top K Frequent Elements 2019/9/27 Array Naive-O(nlogn), HT Heap-O(nlogk), HT Heap 2-O(nlogk), Quickselect-avg O(n), Bucket Sort-O(n), HT-O(n) Note -
367 Easy Valid Perfect Square 2020/5/9 Math Naive-O(n), BinarySearch-O(n) - testcase
👍 368 Medium Largest Divisible Subset 2020/6/13 Array Naive-O(n!), DP-O(n²) Note do it again (DP)
👍 373 Medium Find K Pairs with Smallest Sums 2020/5/3 Array Priority Queue-O(klogk), Heap Merge Sort related to 1439 (competition) testcase, do it again
👍 376 Medium Wiggle Subsequence 2020/9/13 Array Naive-O(n), BottomUpDP-O(n)
👍 378 Medium Kth Smallest Element in a Sorted Matrix TODO Array -
380 Medium Insert Delete GetRandom O(1) 2020/6/12 Design Naive-O(1) testcase, use HT + array
383 Easy Ransom Note 2020/5/4 String Naive-O(n) - testcase
387 Easy First Unique Character in a String 2020/5/5 String Naive-O(n) - testcase
👍 402 Medium Remove K Digits 2020/5/13 String Naive-O(n) do this again
404 Easy Sum of Left Leaves 2020/8/1 BinaryTree Naive-O(n) - testcase
👍 406 Medium * Queue Reconstruction by Height 2020/6/6 Array Sorting-O(n^2), InsertFromLowest-O(nlogn), InsertFromHighest-O(nlogn), Insert-O(n) Note do it again, testcase
👍 416 Medium * Partition Equal Subset Sum TODO Array -
419 Medium Battleships in a Board TODO Array
👍 426 Medium Convert Binary Search Tree to Sorted Doubly Linked List TODO BST Need subscription -
👍 430 Medium * Flatten a Multilevel Doubly Linked List 2020/7/10 Linked List Naive-O(n), Stack-O(n) do it again, testcase
👍 435 Medium * Non-overlapping Intervals TODO Array
👍 438 Medium Find All Anagrams in a String 2020/5/17 String Naive-O(n) -
👍 441 Easy Arranging Coins 2020/7/1 Math Naive-O(n), Binary Search-O(logn), Math-O(1) -
👍 451 Medium Sort Characters By Frequency 2020/5/22 String Naive-O(n), PQ-O(n) testcase
👍 452 Medium Minimum Number of Arrows to Burst Balloons 2020/10/10 Array Naive-O(nlogn) -
460 Hard LFU Cache 2018/6/25 Design Naive Note OrderedDict, LinkedList
461 Easy Hamming Distance 2020/7/5 Bit Manipulation Naive-O(n) testcase
👍 463 Easy Island Perimeter 2020/7/7 Array Naive-O(n), Neighbour-O(n), CountEdge-O(n), StringEdge-O(n) testcase
👍 468 Medium Validate IP Address 2020/6/16 String Naive-O(n) Microsoft Intern Interview todo: pure regex, pure rule
👍 477 Medium Total Hamming Distance TODO Bit Manipulation string approach
👍 494 Medium Target Sum 2020/2/10 Array Naive-O(n²), RecursiveWithMemory-O(l*n), 2D DP-O(l*n), 1D DP-O(l*n) Note, Learn: Queue & Stack more optimization on DP
👍 518 Medium * Coin Change 2 2020/6/7 Array Naive-O(n^t), DP-O(nt) Note do it again (bottom up 1D DP)
👍 503 Medium * Next Greater Element II TODO Array -
520 Easy Detect Capital 2020/8/3 String Naive-O(n), CapitalCount-O(n), RegEx-O(n) -
👍 525 Medium * Contiguous Array 2020/4/13 Array Naive-O(n²), HT-O(n), ExtraArray-O(n), HT2-O(n) Didi Interview do it again
528 Medium Random Pick with Weight 2020/6/5 Design Naive-O(n) testcase
532 Medium K-diff Pairs in an Array 2020/10/3 Array Naive-O(n^2), HT-O(n) testcase
👍 538 Easy Convert BST to Greater Tree TODO BinaryTree same as problem 1038 testcase
👍 540 Medium Single Element in a Sorted Array 2020/5/12 Array Naive-O(n), BinarySearchXOR-O(logn) testcase
👍 543 Easy Diameter of Binary Tree 2020/4/11 Binary Tree DFS-O(n) testcase
559 Easy Maximum Depth of N-ary Tree 2019/11/14 Tree Naive-O(n), DFS-O(n) Note Test
👍 560 Medium Subarray Sum Equals K 2020/4/22 Array BruteForce-O(n^3), CumulativeSum-O(n²), WithoutSpace-O(n²), HT-O(n) Note
563 Easy Binary Tree Tilt 2020/8/1 BinaryTree Naive-O(n) iterative
👍 567 Medium Permutation in String 2020/5/18 String Naive-O(n) testcase
👍 621 Medium * Task Scheduler 2020/7/28 Array Naive-O(nlogn) Note TODO: more solution
👍 624 Easy Maximum Distance in Arrays (premium) 2020/10/5 Array Naive-O(n) -
👍 630 Hard * Course Schedule III TODO Array - - topological sort
👍 662 Medium * Maximum Width of Binary Tree 2020/7/9 Binary Tree Naive-O(n) Note do it again (more elegant way), testcase
👍 673 Medium Number of Longest Increasing Subsequence TODO String
👍 674 Easy Longest Continuous Increasing Subsequence TODO String
👍 678 Medium * Valid Parenthesis String 2020/4/17 String Naive-O(n*3^n), DP-O(n), Greedy-O(n) Note do this again
👍 684 Medium * Redundant Connection 2020/10/18 Graph DSU do this again, DFS, BFS
👍 685 Hard Redundant Connection II TODO Graph DSU
687 Medium Longest Univalue Path TODO Binary Tree Note -
👍 698 Medium * Partition to K Equal Sum Subsets TODO Array -
700 Easy Search in a Binary Search Tree 2020/6/15 Binary Tree Naive-O(logn) testcase
701 Medium * Insert into a Binary Search Tree 2020/10/6 Binary Tree Naive-O(logn), Recursive-O(logn) testcase
703 Easy Kth Largest Element in a Stream 2020/5/8 Design Naive-O(n), Heap-O(n) Note testcase
704 Easy Binary Search 2020/5/9 Array Iterative(<)-O(logn), Recursive(<=)-O(logn) Test
705 Easy Design HashSet 2020/8/2 Design Naive-O(1), With Hash Function-O(1) testcase
733 Easy Flood Fill 2020/5/11 Array Naive-O(n), DFS-O(n), IterativeDFS-O(n) Test
👍 739 Medium Daily Temperatures 2019/12/26 Array Naive-O(n²), Naive2-O(n²), Stack-O(n²) Note, Learn: Queue & Stack -
👍 752 Medium Open the Lock 2019/7/5 Search BFS-O(n²) Note, Learn: Queue & Stack Improve time complexity
👍 763 Medium Partition Labels 2020/9/5 String Naive-O(n)
771 Easy Jewels and Stones 2020/5/2 String Naive-O(n), Naive2-O(n) testcase
👍 784 Easy Letter Case Permutation 2020/7/25 String Naive-O(n) testcase, more elegant way
👍 787 Medium * Cheapest Flights Within K Stops 2020/6/14 Graph Naive-O(V + E), BFS-O(V + E), DP-O(n²), Naive 2-O(V + E) Note do it again
790 Medium Domino and Tromino Tiling TODO Geometry -
👍 797 Medium * All Paths From Source to Target 2020/7/24 Graph Naive-O(2^n), Backtracking-O(2^n) do it again, TODO: iterative version
801 Medium Minimum Swaps To Make Sequences Increasing TODO Array Note -
844 Easy Backspace String Compare 2020/4/9 String Naive-O(n), TwoPointer-O(n) testcase
829 Hard * Consecutive Numbers Sum TODO Math -
👍 857 Hard * Minimum Cost to Hire K Workers 2020/3/17 Array Greedy-O(n²logn), Greedy w/ PQ-O(nlogn) Note -
859 Easy Buddy Strings 2020/10/12 String Naive-O(n^2), Naive-O(n), Better-O(n) testcase
👍 862 Hard * Shortest Subarray with Sum at Least K TODO Array Note Deque
👍 875 Medium Koko Eating Bananas 2020/8/8 Array Naive-O(n), BinarySearch-O(n) testcase
876 Easy Middle of the Linked List 2020/4/8 Linked List Naive-O(n), TwoPointer-O(n) testcase
👍 886 Medium * Possible Bipartition 2020/5/27 Array testcase
👍 901 Medium Online Stock Span 2020/5/19 Design Naive-O(n), Count-O(n), Stack-O(n) testcase
916 Medium Word Subsets 2020/9/5 String Naive-O(n), Improve-O(n), Counter-O(n) testcase
👍 918 Medium * Maximum Sum Circular Subarray 2020/5/15 Array Naive-O(n), MinSumSubarray-O(n) Note use other approach
933 Easy Number of Recent Calls 2020/10/1 Design Naive-O(n), Naive2-O(n), BinarySearch-O(logn), Queue-O(min(n, 3000)), CircularList-O(n) testcase
👍 952 Hard * Largest Component Size by Common Factor TODO Array
957 Medium Prison Cells After N Days 2020/7/3 Array Naive-O(n), LoopDetection-O(n) Note-O(n)
👍 978 Medium Longest Turbulent Subarray TODO String
👍 986 Medium * Interval List Intersections 2020/5/23 Array TwoPointer-O(m+n) Note testcase, do it again
993 Easy Cousins in Binary Tree 2020/5/7 Binary Tree IterativeBFS-O(n), RecursiveDFS-O(n) testcase
👍 994 Medium Rotting Oranges 2020/9/13 Graph Naive-O(V + E)
997 Easy Find the Town Judge 2020/5/10 Array Naive-O(n), Improve-O(n)
1008 Medium Construct Binary Search Tree from Preorder Traversal 2020/4/20 Binary Tree Naive-O(n), Naive2-O(n) Note testcase
1009 Easy Complement of Base 10 Integer (Number Complement) 2020/5/4 BitManipulation Naive-O(n), Pythonic-O(n), BM-O(n) testcase
👍 1010 Easy Pairs of Songs With Total Durations Divisible by 60 2020/10/14 Array Naive-O(n^2), PrefixSum-O(n) testcase
👍 1029 Easy * Two City Scheduling 2020/6/3 Array Naive-O(nlogn), Diff-O(nlogn), Sorting-O(nlogn) -
👍 1035 Medium * Uncrossed Lines 2020/5/25 Array Naive-O(mn), BottomUpDP-O(mn) Note testcase, do it again
👍 1044 Hard Longest Duplicate Substring 2020/6/20 String Naive, BinarySearch-RabinKarp-O(nlogn) Note do it again
1046 Easy Last Stone Weight 2020/4/12 Array Naive-O(n) -
👍 1094 Medium Car Pooling 2020/9/21 Array Naive-O(n) testcase
👍 1143 Medium Longest Common Subsequence 2019/10/22 String BruteForce-O(2ⁿ), DP-O(mn) Note -
👍 1200 Medium * Minimum Absolute Difference TODO Array -
1232 Easy Check If It Is a Straight Line 2020/5/8 Math Naive-O(n) -
👍 1249 Medium * Minimum Remove to Make Valid Parentheses 2020/7/25 String Naive-O(n) testcase, do it again, follow up: O(1) space
👍 1277 Medium Count Square Submatrices with All Ones 2020/5/22 String Naive-O(n^4), DP-O(mn) testcase, do it again
👍 1288 Medium Remove Covered Intervals 2020/10/4 Array Naive-O(n) testcase, do it with other solution
👍 1291 Medium Sequential Digits 2019/12/15 Math Naive-O(n), Recursive-O(nlogn), Naive2-O(n) Weekly Contest 167 testcase, Naive2 (generate sequence in order)
1342 Easy Number of Steps to Reduce a Number to Zero 2020/9/20 Math Naive-O(n) (good for beginners)
👍 1344 Medium Angle Between Hands of a Clock 2020/7/14 Math Naive-O(1) -
👍 1425 Hard Constrained Subsequence Sum TODO Array Note -
👍 1462 Medium * Course Schedule IV TODO Array - - -
👍 1475 Easy * Final Prices With a Special Discount in a Shop 2020/8/22 Array Naive-O(n^2), TwoPointer-O(n^2), Stack-O(n^2) -
👍 1547 Hard Minimum Cost to Cut a Stick 2020/10/17 Array Top-Down DP-O(n^2) FreeWheel 2021 OA, Weekly Contest 201 testcase
👍 1601 Hard Maximum Number of Achievable Transfer Requests 2020/9/28 Graph Naive-O(2^n) testcase
??? Easy Counting Elements 2020/4/7 Array Naive-O(nlogn), SinglePass-O(n) testcase
??? Easy Perform String Shifts 2020/4/15 String Naive-O(n) testcase
??? Easy Leftmost Column with at Least a One 2020/4/21 Interactive Naive-O(mn), BinarySearch-O(n), Improve-O(n+m) Note testcase, do this again
??? Easy First Unique Number 2020/4/28 Design Naive, HT Counter, Double Linked List, Double Linked List + HT Note testcase, improve follow the hint (set, heap)
??? Easy Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree 2020/4/30 Binary Tree Naive testcase, improve (like iterative dfs)
??? Easy Is Subsequence 2020/6/9 String Naive-O(n) testcase

Contest

LeetCode Learn Progress

LeetCode Explore Learn

Introduction to Algorithm

Introduction to Data Structure

Learning about...

Design Date Category Implementaiton Remark TODO
Circular Queue 2019/7/4 Data Structure C++ Note, Design Circular Queue -
Min Stack 2019/12/26 Data Structure C++ Min Stack -

Notes

Data Structure

Algorithm

DIY Progress

Data Structure

Difficulty Problem Date Category Method-TimeComplexity Remark TODO
Easy Linked List 2018/3/12 Linked List Singly-Linked List - Double-Linked List
Medium * Binary Heap (Min/Max Heap) 2018/6/28 Design Binary Heap Note -

Classic Algorithm Problem

Difficulty Problem Date Category Method-TimeComplexity Remark TODO
Easy Linked List 2018/3/12 Linked List Singly-Linked List - Double-Linked List
Medium * Binary Heap (Min/Max Heap) 2018/6/28 Design Binary Heap Note -

Resources

Online Judgement / Assessment

Paid

  • AlgoExpert

  • Grokking Dynamic Programming Patterns for Coding Interviews

    1. 0/1 Knapsack
      • Equal Subset Sum Partition
      • Subset Sum
      • Minimum Subset Sum Difference
      • Count of Subset Sum
      • Target Sum
    2. Unbounded Knapsack
      • Unbounded Knapsack
      • Rod Cutting
      • Coin Change
      • Minimum Coin Change
      • Maximum Ribbon Cut
    3. Fibonacci Numbers (Fibonacci Sequence (eg: House Thief, Jump Game))
      • Fibonacci numbers
      • Staircase
      • Number factors
      • Minimum jumps to reach the end
      • Minimum jumps with fee
      • House thief
    4. Palindromic Subsequence (Shortest Path (eg: Unique Paths I/II))
      • Longest Palindromic Subsequence
      • Longest Palindromic Substring
      • Count of Palindromic Substrings
      • Minimum Deletions in a String to make it a Palindrome
      • Palindromic Partitioning
    5. Longest Common Substring
      • Longest Common Substring
      • Longest Common Subsequence
      • Minimum Deletions & Insertions to Transform a String into another
      • Longest Increasing Subsequence
      • Maximum Sum Increasing Subsequence
      • Shortest Common Super-sequence
      • Minimum Deletions to Make a Sequence Sorted
      • Longest Repeating Subsequence
      • Subsequence Pattern Matching
      • Longest Bitonic Subsequence
      • Longest Alternating Subsequence
      • Edit Distance
      • Strings Interleaving
  • 0/1 Knapsack

  • Unbounded Knapsack

  • Shortest Path (eg: Unique Paths I/II)

  • Fibonacci Sequence (eg: House Thief, Jump Game)

  • Longest Common Substring/Subsequeunce

Course

LeetCode Links

2020 Coronavirus quarantine special events

Top Interview Questions

Detail Solutions

Experience

Others

Usually online judgement TLE limitation is 1 second. => we can estimate the time complexity as the power of ten.

Quick typing math symbol

About

My LeetCode practice source code and notes.

Topics

Resources

Releases

No releases published

Packages

No packages published

Languages

You can’t perform that action at this time.