Skip to content

Greatjian/leetcode_practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode Practice

This is the repository to record and share my LeetCode practice. It's the first step for me to become a software engineer.

The practice is listed based on different topics. I start from easy to medium, finally trying to get rid of the hard problems. The problems in each topic are listed in numerical order.

I use python to solve each answer. As the popular saying goes:

Life is short, you need python.

You can see my attempts for each problem in the Method section, as well as the final solution in Solution part. Final solutions are mostly inspired from the discussion at LeetCode platform, with small modifications based on my understanding and coding style.

I believe self-implementation is as important as coming up with great ideas in terms of solving a problem. Therefore it's highly recommended to write your own version of solutions instead of simply copying the codes. Coding style is another essential part to focus on :)

My harvests for each practice are summarized here.

Catalog:

Useful Summary

Array

set(zip(*board)), set(map(tuple, board))
  • binary search:
lo, hi=0, len(nums)-1
while lo<hi:
    mid=(lo+hi)/2
    if condition...:
        lo=mid+1
    else:
        hi=mid
return lo
  • contiguous subarray: preSum
  • sum of same length: sliding window
Number Name Date
001 two sum 2017.07.10
011 container with most water 2017.07.10
015 3sum 2017.07.10
016 3sum closest 2017.07.10
018 4sum 2017.07.11
026 Remove Duplicates from Sorted Array 2017.07.12
027 Remove Element 2017.07.12
031 Next Permutation 2017.07.17
033 Search in Rotated Sorted Array 2017.07.17
034 Search for a Range 2017.07.18
035 Search Insert Position 2017.07.18
039 Combination Sum 2017.07.19
040 Combination Sum II 2017.07.19
041 First Missing Positive 2018.3.27
042 Trapping Rain Water 2018.3.27
048 Rotate Image 2017.07.20
053 Maximum Subarray 2017.07.20
054 Spiral Matrix 2017.07.20
055 Jump Game 2017.07.20
056 Merge Intervals 2017.07.20
059 Spiral Matrix II 2017.07.20
062 Unique Paths 2017.07.20
063 Unique Paths II 2017.07.20
064 Minimum Path Sum 2017.07.21
066 Plus One 2017.07.21
073 Set Matrix Zeroes 2017.07.21
074 Search a 2D Matrix 2017.07.21
075 Sort Colors 2017.07.21
078 Subsets 2017.07.21
079 Word Search 2017.07.23
080 Remove Duplicates from Sorted Array II 2017.07.24
081 Search in Rotated Sorted Array II 2017.07.24
088 Merge Sorted Array 2017.07.24
090 Subsets II 2017.07.25
118 Pascal's Triangle 2017.07.26
119 Pascal's Triangle II 2017.07.26
120 Triangle 2017.07.26
121 Best Time to Buy and Sell Stock 2017.07.26
122 Best Time to Buy and Sell Stock II 2017.07.26
128 Longest Consecutive Sequence 2018.3.27
152 Maximum Product Subarray 2017.07.26
153 Find Minimum in Rotated Sorted Array 2017.07.26
162 Find Peak Element 2017.07.27
167 Two Sum II - Input array is sorted 2017.07.27
169 Majority Element 2017.07.27
189 Rotate Array 2017.7.30
209 Minimum Size Subarray Sum 2017.7.31
216 Combination Sum III 2017.8.1
217 Contains Duplicate 2017.8.1
219 Contains Duplicate II 2017.8.1
228 Summary Ranges 2017.8.1
229 Majority Element II 2017.8.2
238 Product of Array Except Self 2017.8.2
268 Missing Number 2017.8.2
283 Move Zeroes 2017.8.2
287 Find the Duplicate Number 2017.8.2
289 Game of Life 2017.8.3
380 Insert Delete GetRandom O(1) 2017.8.3
414 Third Maximum Number 2017.8.3
442 Find All Duplicates in an Array 2017.8.3
448 Find All Numbers Disappeared in an Array 2017.8.4
485 Max Consecutive Ones 2017.8.4
495 Teemo Attacking 2017.8.4
532 K-diff Pairs in an Array 2017.8.4
560 Subarray Sum Equals K 2017.8.4
561 Array Partition I 2017.8.4
565 Array Nesting 2017.8.4
566 Reshape the Matrix 2017.8.4
581 Shortest Unsorted Continuous Subarray 2017.8.4
605 Can Place Flowers 2017.8.4
611 Valid Triangle Number 2017.8.5
621 Task Scheduler 2017.8.8
628 Maximum Product of Three Numbers 2017.8.8
643 Maximum Average Subarray I 2017.8.8
644 Maximum Average Subarray II 2018.2.23
697 Degree of an Array 2018.1.15
717 1-bit and 2-bit Characters 2017.12.13
724 Find Pivot Index 2018.4.10

Backtracking

Number Name Date
017 Letter Combinations of a Phone Number 2017.8.9
022 Generate Parentheses 2017.8.9
037 Sudoku Solver 2018.5.15
051 N-Queens 2018.3.27
060 Permutation Sequence 2017.8.10
077 Combinations 2017.8.10
089 Gray Code 2017.8.10
093 Restore IP Addresses 2017.8.13
131 Palindrome Partitioning 2017.8.13
357 Count Numbers with Unique Digits 2017.8.14
401 Binary Watch 2017.8.15
526 Beautiful Arrangement 2017.8.16

Dynamic Programming

  • zero
  • base case
Number Name Date
070 Climbing Stairs 2017.8.17
091 Decode Ways 2017.8.19
097 Interleaving String 2018.2.27
139 Word Break 2017.8.20
198 House Robber 2017.8.21
213 House Robber II 2017.8.22
221 Maximal Square 2017.8.23
264 Ugly Number II 2017.8.26
279 Perfect Squares 2017.8.26
300 Longest Increasing Subsequence 2017.8.27
303 Range Sum Query - Immutable 2017.8.28
304 Range Sum Query 2D - Immutable 2017.8.28
322 Coin Change 2017.8.29
338 Counting Bits 2017.8.30
343 Integer Break 2017.8.30
357 Count Numbers with Unique Digits 2017.8.14
368 Largest Divisible Subset 2017.8.30
375 Guess Number Higher or Lower II 2017.9.1
376 Wiggle Subsequence 2017.9.6
377 Combination Sum IV 2017.9.6
392 Is Subsequence 2017.9.6
413 Arithmetic Slices 2017.9.12
416 Partition Equal Subset Sum 2017.9.13
464 Can I Win 2017.9.14
467 Unique Substrings in Wraparound String 2017.9.15
474 Ones and Zeroes 2017.9.16
486 Predict the Winner 2018.7.23
494 Target Sum 2017.9.17
516 Longest Palindromic Subsequence 2017.9.18
523 Continuous Subarray Sum 2017.9.19
576 Out of Boundary Paths 2017.9.20
638 Shopping Offers 2017.9.26
639 Decode Ways II 2018.2.23
646 Maximum Length of Pair Chain 2017.9.27
647 Palindromic Substrings 2017.9.28
650 2 Keys Keyboard 2017.9.29
673 Number of Longest Increasing Subsequence 2017.9.30
727 Minimum Window Subsequence 2018.2.25
746 Min Cost Climbing Stairs 2018.5.7

Tree

Number Name Date
094 Binary Tree Inorder Traversal 2017.10.1
095 Unique Binary Search Trees II 2017.10.2
096 Unique Binary Search Trees 2017.10.2
098 Validate Binary Search Tree 2017.10.3
100 Same Tree 2017.10.5
101 Symmetric Tree 2017.10.5
102 Binary Tree Level Order Traversal 2017.10.6
103 Binary Tree Zigzag Level Order Traversal 2017.10.9
104 Maximum Depth of Binary Tree 2017.10.10
105 Construct Binary Tree from Preorder and Inorder Traversal 2017.10.10
106 Construct Binary Tree from Inorder and Postorder Traversal 2017.10.11
107 Binary Tree Level Order Traversal II 2017.10.11
108 Convert Sorted Array to Binary Search Tree 2017.10.11
110 Balanced Binary Tree 2017.10.11
111 Minimum Depth of Binary Tree 2017.10.12
112 Path Sum 2017.10.12
113 Path Sum II 2017.10.12
114 Flatten Binary Tree to Linked List 2017.10.12
116 Populating Next Right Pointers in Each Node 2017.10.12
117 Populating Next Right Pointers in Each Node II 2017.10.12
129 Sum Root to Leaf Numbers 2017.10.12
144 Binary Tree Preorder Traversal 2017.10.9
145 Binary Tree Postorder Traversal 2017.10.9
173 Binary Search Tree Iterator 2017.10.14
199 Binary Tree Right Side View 2017.10.15
222 Count Complete Tree Nodes 2017.10.16
226 Invert Binary Tree 2017.10.16
230 Kth Smallest Element in a BST 2017.10.16
235 Lowest Common Ancestor of a Binary Search Tree 2017.10.16
236 Lowest Common Ancestor of a Binary Tree 2017.10.16
257 Binary Tree Paths 2017.10.16
337 House Robber III 2017.10.16
404 Sum of Left Leaves 2017.10.17
437 Path Sum III 2017.10.18
449 Serialize and Deserialize BST 2017.10.19
450 Delete Node in a BST 2017.10.19
501 Find Mode in Binary Search Tree 2017.10.20
508 Most Frequent Subtree Sum 2017.10.21
513 Find Bottom Left Tree Value 2017.10.21
515 Find Largest Value in Each Tree Row 2017.10.21
538 Convert BST to Greater Tree 2017.10.21
543 Diameter of Binary Tree 2017.10.21
563 Binary Tree Tilt 2017.10.21
572 Subtree of Another Tree 2017.10.21
606 Construct String from Binary Tree 2017.10.21
617 Merge Two Binary Trees 2017.10.21
623 Add One Row to Tree 2017.10.22
637 Average of Levels in Binary Tree 2017.10.22
652 Find Duplicate Subtrees 2017.10.22
652 Two Sum IV - Input is a BST 2017.10.22
654 Maximum Binary Tree 2017.10.23
655 Print Binary Tree 2017.10.23
662 Maximum Width of Binary Tree 2017.10.23
669 Trim a Binary Search Tree 2017.10.23
671 Second Minimum Node In a Binary Tree 2017.10.23
687 Longest Univalue Path 2017.10.24

String

''.join(s)
s.split()
map(str/int/function, iterable)
ord(), chr()
string.upper()/lower()
zip()/zipped(*)
any()/all()
sorted(iterable, key=len/lambda..., reverse=True)
Number Name Date
003 Longest Substring Without Repeating Characters 2017.10.25
005 Longest Palindromic Substring 2017.10.28
006 ZigZag Conversion 2017.10.29
008 String to Integer (atoi) 2017.10.30
012 Integer to Roman 2017.10.31
013 Roman to Integer 2017.10.31
014 Longest Common Prefix 2017.11.1
020 Valid Parentheses 2017.11.2
028 Implement strStr() 2017.11.2
038 Count and Say 2017.11.2
043 Multiply Strings 2017.11.2
049 Group Anagrams 2017.11.2
058 Length of Last Word 2017.11.3
067 Add Binary 2017.11.3
071 Simplify Path 2017.11.3
076 Minimum Window Substring 2018.2.25
125 Valid Palindrome 2017.11.3
151 Reverse Words in a String 2017.11.3
165 Compare Version Numbers 2017.11.3
227 Basic Calculator II 2017.11.6
344 Reverse String 2017.11.6
345 Reverse Vowels of a String 2017.11.6
383 Ransom Note 2017.11.6
385 Mini Parser 2017.11.7
434 Number of Segments in a String 2017.11.7
443 String Compression 2017.11.8
459 Repeated Substring Pattern 2017.11.9
468 Validate IP Address 2017.11.9
520 Detect Capital 2017.11.9
521 Longest Uncommon Subsequence I 2017.11.9
522 Longest Uncommon Subsequence II 2017.11.9
537 Complex Number Multiplication 2017.11.11
539 Minimum Time Difference 2017.11.12
541 Reverse String II 2017.11.12
551 Student Attendance Record I 2017.11.12
553 Optimal Division 2017.11.12
556 Next Greater Element III 2017.11.12
557 Reverse Words in a String III 2017.11.12
583 Delete Operation for Two Strings 2017.11.12
609 Find Duplicate File in System 2017.11.13
657 Judge Route Circle 2017.11.13
678 Valid Parenthesis String 2017.11.13
680 Valid Palindrome II 2017.11.13
686 Repeated String Match 2017.11.13
696 Count Binary Substrings 2017.11.14
722 Remove Comments 2017.11.14

Hash Table

set()
collections.defaultdict(int/list/lambda...)
collections.Counter()
d.keys()/values()/items()/elements()
set1()/dict1() +/-/&/| set2()/dict2()
sorted(d.keys(), key=lambda i: (-d[i], i))[:k]
Number Name Date
030 Substring with Concatenation of All Words 2018.5.15
036 Valid Sudoku 2017.11.19
136 Single Number 2017.11.19
138 Copy List with Random Pointer 2017.11.19
166 Fraction to Recurring Decimal 2017.11.19
187 Repeated DNA Sequences 2017.11.19
202 Happy Number 2017.11.19
204 Count Primes 2017.11.19
205 Isomorphic Strings 2017.11.20
242 Valid Anagram 2017.11.20
274 H-Index 2017.11.20
290 Word Pattern 2017.11.20
299 Bulls and Cows 2017.11.21
347 Top K Frequent Elements 2017.11.21
349 Intersection of Two Arrays 2017.11.21
350 Intersection of Two Arrays II 2017.11.21
389 Find the Difference 2017.11.21
409 Longest Palindrome 2017.11.21
438 Find All Anagrams in a String 2017.11.21
447 Number of Boomerangs 2017.11.22
451 Sort Characters By Frequency 2017.11.22
454 4Sum II 2017.11.22
463 Island Perimeter 2017.11.22
500 Keyboard Row 2017.11.22
525 Contiguous Array 2017.11.22
- - Happy Thanksgiving
535 Encode and Decode TinyURL 2017.11.27
554 Brick Wall 2017.11.27
575 Distribute Candies 2017.11.27
599 Minimum Index Sum of Two Lists 2017.11.27
645 Set Mismatch 2017.11.27
648 Replace Words 2017.11.27
676 Implement Magic Dictionary 2017.11.27
690 Employee Importance 2017.11.27
692 Top K Frequent Words 2017.11.28
718 Maximum Length of Repeated Subarray 2017.11.28
720 Longest Word in Dictionary 2017.11.29
734 Sentence Similarity 2017.11.30
760 Find Anagram Mappings 2018.4.4

Math

  • Division
if token=='/':
    if t2/t1<0 and t2%t1:
        val=str(t2/t1+1)
    else:
        val=str(t2/t1)
Number Name Date
002 Add Two Numbers 2017.11.30
007 Reverse Integer 2017.11.30
009 Palindrome Number 2017.12.1
029 Divide Two Integers 2017.12.1
050 Pow(x, n) 2017.12.2
069 Sqrt(x) 2017.12.3
168 Excel Sheet Column Title 2017.12.3
171 Excel Sheet Column Number 2017.12.3
172 Factorial Trailing Zeroes 2017.12.3
223 Rectangle Area 2017.12.3
231 Power of Two 2017.12.4
258 Add Digits 2017.12.4
313 *Super Ugly Number 2017.12.5
- - Happy Final
319 Bulb Switcher 2017.12.11
326 Power of Three 2017.12.11
365 Water and Jug Problem 2017.12.13
367 Valid Perfect Square 2017.12.13
- - Happy Winter Vacation
396 Rotate Function 2018.1.11
397 Integer Replacement 2018.1.11
400 Nth Digit 2018.1.11
415 Add Strings 2018.1.12
423 Reconstruct Original Digits from English 2018.1.12
441 Arranging Coins 2018.1.14
453 Minimum Moves to Equal Array Elements 2018.1.15
462 Minimum Moves to Equal Array Elements II 2018.1.15
507 Perfect Number 2018.1.15
592 Fraction Addition and Subtraction 2018.1.15
593 Valid Square 2018.1.15
598 Range Addition II 2018.1.15
640 Solve the Equation 2018.1.15
670 Maximum Swap 2018.1.16
728 Self Dividing Numbers 2018.1.16
754 Reach a Number 2018.1.16

Divide and Conquer

  • binary search
  • mergesort and count/Binary indexed tree(bisect.bisect_right(s, num))
  • defensive coding:
if not hp or hp[0]:
    ...
    
while hp:
    hp.pop()
    ...
Number Name Date
327 Count of Range Sum 2018.2.5
084 Largest Rectangle in Histogram 2018.2.5
493 Reverse Pairs 2018.2.5
315 Count of Smaller Numbers After Self 2018.2.5
004 Median of Two Sorted Arrays 2018.2.7
023 Merge k Sorted Lists 2018.2.7
218 The Skyline Problem 2018.2.9
312 Burst Balloons 2018.2.9

Design

  • trade-off between functions
Number Name Date
155 Min Stack 2018.1.23
170 Two Sum III - Data structure design 2018.1.24
208 Implement Trie (Prefix Tree) 2018.1.26
211 Add and Search Word - Data structure design 2018.1.26
225 Implement Stack using Queues 2018.1.28
232 Implement Queue using Stacks 2018.1.28
244 Shortest Word Distance II 2018.1.30
251 Flatten 2D Vector 2018.2.1
146 LRU Cache 2018.2.20
297 Serialize and Deserialize Binary Tree 2018.2.20
341 Flatten Nested List Iterator 2018.2.21
295 Find Median from Data Stream 2018.2.21

Order

  • dummy node:
dummy=ListNode(0)
dummy.next=head
# code here
...
return dummy.next
  • fast and slow(prev) (cycle, mid node)
  • int(binary string, 2)
  • bin(int) -> string
  • dfs and bfs iteration:
while stack:
    x, y=stack.pop()
    for (dx, dy) in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        if x+dx>=0 and x+dx<m and y+dy>=0 and y+dy<n and grid[x+dx][y+dy]=='1':
            grid[x+dx][y+dy]='0'
            stack.append((x+dx, y+dy))  
  • bit manipulation:
delete the last zero:
n&=n-1
Number Name Date Topics
010 Regular Expression Matching 2018.2.14 Dynamic Programming, String, Backtracking
019 Remove Nth Node From End of List 2018.1.16 Linked List, Two Pointers
021 Merge Two Sorted Lists 2018.1.17 Linked List
024 Swap Nodes in Pairs 2018.1.17 Linked List
061 Rotate List 2018.1.16 Linked List, Two Pointers
072 Edit Distance 2018.2.14 Dynamic Programming, String
082 Remove Duplicates from Sorted List II 2018.1.19 Linked List
083 Remove Duplicates from Sorted List 2018.1.19 Linked List
085 Maximal Rectangle 2018.2.14 Dynamic Programming, Array, Hash Table, Stack
086 Partition List 2018.1.19 Linked List, Two Pointers
*092 Reverse Linked List II 2018.1.19 Linked List
109 Convert Sorted List to Binary Search Tree 2018.1.20 Linked List, Depth-first Search
115 Distinct Subsequences 2018.2.18 Dynamic Programming, String
*126 Word Ladder II 2018.2.3 Array, String, Backtracking, Breadth-first Search
127 Word Ladder 2018.1.20 Breadth-first Search
130 Surrounded Regions 2018.1.21 Breadth-first Search, Depth-first Search
133 Clone Graph 2018.1.21 Breadth-first Search, Depth-first Search, Graph
134 Gas Station 2018.1.21 Greedy
137 Single Number II 2018.1.21 Bit Manipulation
141 Linked List Cycle 2018.1.21 Linked List, Two Pointers
142 Linked List Cycle II 2018.1.22 Linked List, Two Pointers
143 Reorder List 2018.1.22 Linked List
147 Insertion Sort List 2018.1.23 Linked List, Sort
148 Sort List 2018.1.23 Linked List, Sort
149 Max Points on a Line 2018.7.16 Hash Table, Math
150 Evaluate Reverse Polish Notation 2018.1.23 Stack
*156 Binary Tree Upside Down 2018.1.23 Tree
157 Read N Characters Given Read4 2018.1.23 String
160 Intersection of Two Linked Lists 2018.1.23 Linked List
161 One Edit Distance 2018.1.24 String
163 Missing Ranges 2018.1.24 Array
186 Reverse Words in a String II 2018.1.24 String
190 Reverse Bits 2018.1.25 Bit Manipulation
191 Number of 1 Bits 2018.1.25 Bit Manipulation
200 Number of Islands 2018.1.25 Breadth-first Search, Depth-first Search, Union Find
201 Bitwise AND of Numbers Range 2018.1.25 Bit Manipulation
203 Remove Linked List Elements 2018.1.25 Linked List
206 Reverse Linked List 2018.1.22 Linked List
207 Course Schedule 2018.1.25 Breadth-first Search, Depth-first Search, Graph, Topological Sort
210 Course Schedule II 2018.1.26 Breadth-first Search, Depth-first Search, Graph, Topological Sort
215 Kth Largest Element in an Array 2018.1.27 Divide and Conquer, Heap
220 Contains Duplicate III 2018.1.28 Binary Search Tree
234 Palindrome Linked List 2018.1.28 Linked List, Two Pointers
237 Delete Node in a Linked List 2018.1.29 Linked List
240 Search a 2D Matrix II 2018.1.29 Binary Search, Divide and Conquer
241 Different Ways to Add Parentheses 2018.1.30 Divide and Conquer
243 Shortest Word Distance 2018.1.30 Array
245 Shortest Word Distance III 2018.1.30 Array
246 Strobogrammatic Number 2018.1.31 Hash Table, Math
247 Strobogrammatic Number II 2018.1.31 Recursion, Math
249 Group Shifted Strings 2018.2.1 Hash Table, String
250 Count Univalue Subtrees 2018.2.1 Tree
252 Meeting Rooms 2018.2.1 Sort
253 Meeting Rooms II 2018.2.1 Heap, Greedy, Sort
254 Factor Combinations 2018.2.1 Backtracking
*255 Verify Preorder Sequence in Binary Search Tree 2018.2.2 Stack, Tree
256 Paint House 2018.2.2 Dynamic Programming
259 3Sum Smaller 2018.2.8 Array, Two Pointers
265 Paint House II 2018.2.2 Dynamic Programming
266 Palindrome Permutation 2018.2.8 Hash Table
267 Palindrome Permutation II 2018.2.8 Backtracking
270 Closest Binary Search Tree Value 2018.2.8 Binary Search, Tree
272 Closest Binary Search Tree Value II 2018.2.8 Stack, Tree
292 Nim Game 2018.4.4 Brainteaser
305 Number of Islands II 2018.7.24 Union Find
307 Range Sum Query - Mutable 2018.2.26 Binary Indexed Tree
308 Range Sum Query 2D - Mutable 2018.2.27 Binary Indexed Tree
316 Remove Duplicate Letters 2018.5.7 Stack, Greedy
323 Number of Connected Components in an Undirected Graph 2018.3.22 Breadth-first Search, Depth-first Search, Graph
340 Longest Substring with At Most K Distinct Characters 2018.7.23 Hash Table, String
356 Line Reflection 2018.7.16 Hash Table, Math
359 Logger Rate Limiter 2018.7.23 Hash Table, Design
378 Kth Smallest Element in a Sorted Matrix 2018.2.18 Binary Search, Heap
387 First Unique Character in a String 2018.5.7 Hash Table, String
398 Random Pick Index 2018.7.8 Reservoir Sampling
399 Evaluate Division 2018.7.23 Depth-first Search, Union Find
402 Remove K Digits 2018.6.17 Stack, Greedy
406 Queue Reconstruction by Height 2018.5.7 Greedy
418 Sentence Screen Fitting 2018.7.23 Dynamic Programming
461 Hamming Distance 2018.4.4 Bit Manipulation
477 Total Hamming Distance 2018.4.4 Bit Manipulation
490 The Maze 2018.7.23 Breadth-first Search, Depth-first Search
496 Next Greater Element I 2018.7.23 Stack
499 The Maze III 2018.7.23 Breadth-first Search, Depth-first Search
503 Next Greater Element II 2018.7.23 Stack
505 The Maze II 2018.7.23 Breadth-first Search, Depth-first Search
684 Redundant Connection 2018.7.23 Union Find
685 Redundant Connection II 2018.7.23 Union Find
719 Find K-th Smallest Pair Distance 2018.2.18 Binary Search, Heap
737 Sentence Similarity II 2018.7.28 Union Find, Depth-first Search
753 Cracking the Safe 2018.7.23 Depth-first Search
763 Partition Labels 2018.5.7 Two Pointers, Greedy
864 Random Pick with Blacklist 2018.7.8 Hash Table, Random

Leetcode Contest

Number Name Date Topics
Weekly Contest 68 766. Toeplitz Matrix 2018.1.21 Array
- 767. Reorganize String 2018.1.21 String, Heap, Greedy, Sort
- 769. Max Chunks To Make Sorted 2018.1.21 Array
- 768. Max Chunks To Make Sorted II 2018.1.21 Array
Weekly Contest 69 771. Jewels and Stones 2018.1.28 Hash Table
- 775. Global and Local Inversions 2018.1.28 Array, Math
- 773. Sliding Puzzle 2018.1.28 Breadth-first Search
- 774. Minimize Max Distance to Gas Station 2018.1.28 Binary Search
Weekly Contest 70 779. K-th Symbol in Grammar 2018.2.4 Recursion
- 777. Swap Adjacent in LR String 2018.2.4 Brainteaser
- 776. Split BST 2018.2.4 Binary Search Tree
- 778. Swim in Rising Water 2018.2.4 Binary Search, Heap, Depth-first Search
Weekly Contest 71 783. Minimum Distance Between BST Nodes 2018.2.10 Binary Search Tree
- 781. Rabbits in Forest 2018.2.10
- 780. Reaching Points 2018.2.10
- 782. Transform to Chessboard 2018.2.10
Weekly Contest 72 784. Letter Case Permutation 2018.2.18 Backtracking
- 785. Is Graph Bipartite? 2018.2.18 Stack
- 787. Cheapest Flights Within K Stops 2018.2.18 Heap, Breadth-first Search
- 786. K-th Smallest Prime Fraction 2018.2.18 Heap, Binary Search
Weekly Contest 73 788. Rotated Digits 2018.2.25
- 789. Escape The Ghosts 2018.2.25
- 791. Custom Sort String 2018.2.25
- 790. Domino and Tromino Tiling 2018.2.25
Weekly Contest 74 794. Valid Tic-Tac-Toe State 2018.3.6 Math, Recursion
- 792. Number of Matching Subsequences 2018.3.6 Array
- 795. Number of Subarrays with Bounded Maximum 2018.3.6 Array
- 793. Preimage Size of Factorial Zeroes Function 2018.3.6 Binary Search
Weekly Contest 75 796. Rotate String 2018.3.12
- 797. All Paths From Source to Target 2018.3.12
- 799. Champagne Tower 2018.3.12
- 798. Smallest Rotation with Highest Score 2018.3.12
Weekly Contest 76 800. Similar RGB Color 2018.3.19 String, Math
- 801. Minimum Swaps To Make Sequences Increasing 2018.3.19 Dynamic Programming
- 802. Find Eventual Safe States 2018.3.19 Depth-first Search, Graph
Weekly Contest 77 804. Unique Morse Code Words 2018.3.26
- 806. Number of Lines To Write String 2018.3.26
- 807. Max Increase to Keep City Skyline 2018.3.26
- 805. Split Array With Same Average 2018.3.26
Weekly Contest 78 811. Subdomain Visit Count 2018.4.3 String
- 809. Expressive Words 2018.4.3 String
- 808. Soup Servings 2018.4.3 Dynamic Programming
- 810. Chalkboard XOR Game 2018.4.3 Math
Weekly Contest 79 812. Largest Triangle Area 2018.4.9 Math
- 814. Binary Tree Pruning 2018.4.9 Tree
- 813. Largest Sum of Averages 2018.4.9 Dynamic Programming
- 815. Bus Routes 2018.4.9 Breadth-first Search
Weekly Contest 80 819. Most Common Word 2018.4.18 String
- 817. Linked List Components 2018.4.18 Linked List
- 816. Ambiguous Coordinates 2018.4.18 String
- 818. Race Car 2018.4.18 Dynamic Programming
Weekly Contest 81 821. Shortest Distance to a Character 2018.4.24
- 822. Card Flipping Game 2018.4.24
- 820. Short Encoding of Words 2018.4.24
- 823. Binary Trees With Factors 2018.4.24
Weekly Contest 82 824. Goat Latin 2018.4.28
- 825. Friends Of Appropriate Ages 2018.4.28
- 826. Most Profit Assigning Work 2018.4.28
- 827. Making A Large Island 2018.4.28
Weekly Contest 83 830. Positions of Large Groups 2018.5.6 Array
- 831. Masking Personal Information 2018.5.6 String
- 829. Consecutive Numbers Sum 2018.5.6 Math
- 828. Unique Letter String 2018.5.6 Two Pointers
Weekly Contest 84 832. Flipping an Image 2018.5.13
- 833. Find And Replace in String 2018.5.13
- 835. Image Overlap 2018.5.13
- 834. Sum of Distances in Tree 2018.5.13
Weekly Contest 85 836. Rectangle Overlap 2018.5.21 Math
- 838. Push Dominoes 2018.5.21 Two Pointers, Dynamic Programming
- 837. New 21 Game 2018.5.21 Dynamic Programming
- 839. Similar String Groups 2018.5.21 Graph, Union Find
Weekly Contest 86 840. Magic Squares In Grid 2018.5.28 Array
- 841. Keys and Rooms 2018.5.28 Depth-first Search, Graph
- 842. Split Array into Fibonacci Sequence 2018.5.28 String, Greedy
- 843. Guess the Word 2018.5.28 Minimax
Weekly Contest 87 844. Backspace String Compare 2018.6.2 Two Pointers, Stack
- 845. Longest Mountain in Array 2018.6.2 Two Pointers
- 846. Hand of Straights 2018.6.2 Hash Table
- 847. Shortest Path Visiting All Nodes 2018.6.2 Dynamic Programming, Breadth-first Search
Weekly Contest 88 848. Shifting Letters 2018.6.10 String
- 849. Maximize Distance to Closest Person 2018.6.10 Array
- 851. Loud and Rich 2018.6.10 Depth-first Search
- 850. Rectangle Area II 2018.6.10 Segment Tree
Weekly Contest 89 852. Peak Index in a Mountain Array 2018.6.17 Binary Search
- 853. Car Fleet 2018.6.17 Stack
- 855. Exam Room 2018.6.17 Map
- 854. K-Similar Strings 2018.6.17 Breadth-first Search, Graph
Weekly Contest 90 859. Buddy Strings 2018.6.27 String
- 856. Score of Parentheses 2018.6.27 String, Stack
- 858. Mirror Reflection 2018.6.27 Math
- 857. Minimum Cost to Hire K Workers 2018.6.27 Heap
Weekly Contest 91 860. Lemonade Change 2018.7.3 Greedy
- 863. All Nodes Distance K in Binary Tree 2018.7.3 Tree, Depth-first Search, Breadth-first Search
- 861. Score After Flipping Matrix 2018.7.3 Greedy
- 862. Shortest Subarray with Sum at Least K 2018.7.3 Deque
Weekly Contest 92 867. Transpose Matrix 2018.7.8 Array
- 865. Smallest Subtree with all the Deepest Nodes 2018.7.8 Tree
- 866. Prime Palindrome 2018.7.8 Math
- 864. Shortest Path to Get All Keys 2018.7.8 Heap, Breadth-first Search
Weekly Contest 93 868. Binary Gap 2018.7.16 Math
- 869. Reordered Power of 2 2018.7.16 Math
- 870. Advantage Shuffle 2018.7.16 Array, Greedy
- 871. Minimum Number of Refueling Stops 2018.7.16 Dynamic Programming, Heap
Weekly Contest 94 872. Leaf-Similar Trees 2018.7.22
- 874. Walking Robot Simulation 2018.7.22
- 875. Koko Eating Bananas 2018.7.22
- 873. Length of Longest Fibonacci Subsequence 2018.7.22
Weekly Contest 95 876. Middle of the Linked List 2018.7.28 Linked List
- 877. Stone Game 2018.7.28 Math, Dynamic Programming
- 878. Nth Magical Number 2018.7.28 Math, Binary Search
- 879. Profitable Schemes 2018.7.28 Dynamic Programming
Weekly Contest 96 887. Projection Area of 3D Shapes 2018.8.5 Math
- 885. Boats to Save People 2018.8.5 Two Pointers, Greedy
- 884. Decoded String at Index 2018.7.28 Stack
- 886. Reachable Nodes In Subdivided Graph 2018.7.28 Heap

Releases

No releases published

Packages

No packages published