Skip to content

drinkbeer/CodingQuestion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Interview Preparation

Sharing some common interview preparation materials through this reporsity.

Preparation Areas

  1. Data Structure and Algorithm
  2. System Design && Object-Oriented Design
  3. Computer Science and programming language knowledge, APIs, best practice, JVM mechanism & turning
  4. Behavior Question & Project/Technical Knowledge Dive Deep

Preparation

Strategies:

  1. Easy + Medium first, then Hard. Focus on Medium level.
  2. In preparation stage, categories based; in final stage (one or two weeks before interviewing), company tag based.
  3. Think 10 - 20 minutes, if no clues, read the discussions. Do not spend more than 30 minutes on each problem.
  4. Write all solutions.
  5. Summarize similar problems.

Categories (Data Structure & Algorithms):

  1. Sort
    • Quick Sort, Merge Sort
    • Quick Select
  2. LinkedList
  3. Heap (or Priority Queue), Stack, Queue, Hash (HashMap, HashSet)
  4. Binary Search
  5. 2 Pointers
    • 2 Pointers
    • Sliding Window
  6. BFS
  7. DFS
  8. DP

Others (Data Structure & Algorithms & Design):

  1. Union Find
  2. Trie
  3. Monotone Stack / Queue
  4. Sweep Line
  5. TreeMap
  6. Bit Manipulation
  7. Math
  8. Randomized
  9. Design
  10. Prefix Sum
  11. Segment Tree, Binary Index Tree, Minimum Spanning Tree

Array

Array includes N-Sum series, operation to array(rotate or pivot). DFS or BFS search a subset of array, e.g combination.
Binary Search is also a hot topic for sorted array. When see the coding problem requires O(logN) time complexity to search something in a sorted array, then it's probably using Binary Search.
Give an array, always ask interview: if the array is sorted? Could we sort the array if necessary? If the array is empty or null? If that could be huge array that will be out of memory?

Note:

  1. If a topic is about DP or Greedy, it's put to DP section, e.g. 45. Jump Game II.

K-Sum problem summary

Question Solution Tags
★1.Two Sum LeetCode-1-Two-Sum.java Array, HashMap
4. Median of Two Sorted Arrays LeetCode-4-Median-of-Two-Sorted-Arrays.java Array
11 Container With Most Water LeetCode-11-Container-With-Most-Water.java Array, Two Pointers
★15.3Sum LeetCode-15-3Sum.java Array, Three Pointers
16 3Sum Closest LeetCode-16-3Sum-Closest.java Array, Three Pointers
18.4Sum LeetCode-18-4Sum.java Four Pointers
26.Remove Duplicates from Sorted Array LeetCode-26-Remove-Duplicates-from-Sorted-Array.java One Pointers, LC80
27.Remove Element LeetCode-27-Remove-Element.java One or Two Pointers
31.Next Permutation LeetCode-31-Next-Permutation.java Array, Hard to Understand
33.Search in Rotated Sorted Array LeetCode-33-Search-in-Rotated-Sorted-Array.java Binary Search, LC81
34.Search for a Range LeetCode-34-Search-for-a-Range.java Binary Search
35 Search Insert Position LeetCode-35-Search-Insert-Position.java Binary Search
36. Valid Sudoku LeetCode-36-Valid-Sudoku.java Array
37. Sudoku Solver LeetCode-37-Sudoku-Solver.java Array, DFS
39.Combination Sum I LeetCode-39-Combination-Sum-I.java DFS
40.Combination Sum II LeetCode-40-Combination-Sum-II.java DFS
41. First Missing Positive LeetCode-41-First-Missing-Positive.java Array, rearrange the array
42. Trapping Rain Water LeetCode-42-Trapping-Rain-Water.java Two Pointers, Two Way Scanning
46.Permutations LeetCode-46-Permutations.java DFS, BFS
47.Permutations II LeetCode-47-Permutations-II.java DFS, BFS
48 Rotate Image LeetCode-48-Rotate-Image.java Array
51. N-Queens LeetCode-51-N-Queens.java Array
54 Spiral Matrix LeetCode-54-Spiral-Matrix.java Array
59 Spiral Matrix II LeetCode-59-Spiral-Matrix-II.java Array
56.Merge Intervals LeetCode-56-Merge-Intervals.java Array
57.Insert Interval LeetCode-57-Insert-Interval.java Array
73.Set Matrix Zeroes LeetCode-73-Set-Matrix-Zeroes.java Array
74.Search a 2D Matrix LeetCode-74-Search-a-2D-Matrix.java Array, Binary Search
75 Sort Colors LeetCode-75-Sort-Colors.java Array, Two Pointers
79.Word Search LeetCode-79-Word-Search.java Array, DFS
80.Remove Duplicates from Sorted Array II LeetCode-80-Remove-Duplicates-from-Sorted-Array-II.java Array, One Pointer, LC26
81.Search in Rotated Sorted Array II LeetCode-81-Search-in-Rotated-Sorted-Array-II.java Array, Binary Search, LC33
84. Largest Rectangle in Histogram LeetCode-84-Largest-Rectangle-in-Histogram.java Array, Stack, Two Way Scan
88.Merge Sorted Array LeetCode-88-Merge-Sorted-Array.java Array, Two Pointers
118.Pascal's Triangle LeetCode-118-Pascals-Triangle.java Array
119.Pascal's Triangle II LeetCode-119-Pascals-Triangle-II.java Array
153. Find Minimum in Rotated Sorted Array LeetCode-153-Find-Minimum-in-Rotated-Sorted-Array.java Array
154. Find Minimum in Rotated Sorted Array II LeetCode-154-Find-Minimum-in-Rotated-Sorted-Array-II.java Array
162. Find Peak Element LeetCode-162-Find-Peak-Element.java Array, Binary Search
163. Missing Ranges LeetCode-163-Missing-Ranges.java Array
167.Two Sum II - Input array is sorted LeetCode-167-Two-Sum-II-Input-array-is-sorted.java Two Pointers
170.Two Sum III - Data structure design LeetCode-170-Two-Sum-III-Data-structure-design.java HashMap
259.3Sum Smaller LeetCode-259-3Sum-Smaller.java Two Pointers
169. Majority Element LeetCode-169-Majority-Element.java Array, Bit Manipulation
189.Rotate Array LeetCode-189-Rotate-Array.java Array
200.Number of Islands LeetCode-200-Number-of-Islands.java DFS
209.Minimum Size Subarray Sum LeetCode-209-Minimum-Size-Subarray-Sum.java Array, Two Pointers, Binary Search
212.Word Search II LeetCode-212-Word-Search-II.java Not yet, hard
215. Kth Largest Element in an Array LeetCode-215-Kth-Largest-Element-in-an-Array.java QuickSelect
229. Majority Element II LeetCode-229-Majority-Element-II.java Array, Moore Voting
238.Product of Array Except Self LeetCode-238-Product-of-Array-Except-Self.java Array
240.Search a 2D Matrix II LeetCode-240-Search-a-2D-Matrix-II.java Array
243. Shortest Word Distance LeetCode-243-Shortest-Word-Distance.java Array
244. Shortest Word Distance II LeetCode-244-Shortest-Word-Distance-II.java Array, Design
245. Shortest Word Distance III LeetCode-245-Shortest-Word-Distance-III.java Array
252.Meeting Rooms LeetCode-252-Meeting-Rooms.java Array, LC 56
253.Meeting Rooms II LeetCode-253-Meeting-Rooms-II.java Array, Heap, LC 56
268.Missing Number LeetCode-268-Missing-Number.java Array
277. Find the Celebrity LeetCode-277-Find-the-Celebrity.java Array
283.Move Zeroes LeetCode-283-Move-Zeroes.java Array
287.Find the Duplicate Number LeetCode-287-Find-the-Duplicate-Number.java Array
289. Game of Life LeetCode-289-Game-of-Life.java Array
296. Best Meeting Point LeetCode-296-Best-Meeting-Point.java Array
★315. Count of Smaller Numbers After Self LeetCode-315-Count-of-Smaller-Numbers-After-Self.java Array, MergeSort, BST, BIT
324. Wiggle Sort II LeetCode-324-Wiggle-Sort-II.java Array, Sort
★327. Count of Range Sum LeetCode-327-Count-of-Range-Sum.java Array, MergeSort, BST, BIT
329. Longest Increasing Path in a Matrix LeetCode-329-Longest-Increasing-Path-in-a-Matrix.java Array, DFS
339. Nested List Weight Sum LeetCode-339-Nested-List-Weight-Sum.java Recursive
341. Flatten Nested List Iterator LeetCode-341-Flatten-Nested-List-Iterator.java Array
349. Intersection of Two Arrays LeetCode-349-Intersection-of-Two-Arrays.java Array
350. Intersection of Two Arrays II LeetCode-350-Intersection-of-Two-Arrays-II.java Array
352. Data Stream as Disjoint Intervals LeetCode-352-Data-Stream-as-Disjoint-Intervals.java Array, TreeMap
364. Nested List Weight Sum II LeetCode-364-Nested-List-Weight-Sum-II.java Recursive, Iterative
378. Kth Smallest Element in a Sorted Matrix LeetCode-378-Kth-Smallest-Element-in-a-Sorted-Matrix.java Heap, Binary Search
384. Shuffle an Array LeetCode-384-Shuffle-an-Array.java Array
412. Fizz Buzz LeetCode-412-Fizz-Buzz.java Iterative
419. Battleships in a Board LeetCode-419-Battleships-in-a-Board.java Iterative
435. Non-overlapping Intervals LeetCode-435-Non-overlapping-Intervals.java Iterative
463. Island Perimeter LeetCode-463-Island-Perimeter.java Recursive
448. Find All Numbers Disappeared in an Array LeetCode-448-Find-All-Numbers-Disappeared-in-an-Array.java Arraay
★493. Reverse Pairs LeetCode-493-Reverse-Pairs.java Array, MergeSort, BST, BIT
498. Diagonal Traverse LeetCode-498-Diagonal-Traverse.java Array
540. Single Element in a Sorted Array LeetCode-540-Single-Element-in-a-Sorted-Array.java Binary Search
560. Subarray Sum Equals K LeetCode-560-Subarray-Sum-Equals-K.java Culmulative Sum
661. Image Smoother LeetCode-661-Image-Smoother.java Array
674. Longest Continuous Increasing Subsequence LeetCode-674-Longest-Continuous-Increasing-Subsequence.java Array
670. Maximum Swap LeetCode-670-Maximum-Swap.java Array
694. Number of Distinct Islands LeetCode-694-Number-of-Distinct-Islands.java Recursive
698. Partition to K Equal Sum Subsets LeetCode-698-Partition-to-K-Equal-Sum-Subsets.java Recursive
719. Find K-th Smallest Pair Distance LeetCode-719-Find-K-th-Smallest-Pair-Distance.java Array, Binary Search
724. Find Pivot Index LeetCode-724-Find-Pivot-Index.java Array
744. Find Smallest Letter Greater Than Target LeetCode-744-Find-Smallest-Letter-Greater-Than-Target.java Array, Binary Search
911. Online Election LeetCode-911-Online-Election.java Array, Binary Search, TreeMap
912. Sort an Array LeetCode-912-Sort-an-Array.java Array, Sort
915. Partition Array into Disjoint Intervals LeetCode-915-Partition-Array-into-Disjoint-Intervals.java Array
977. Squares of a Sorted Array LeetCode-977-Squares-of-a-Sorted-Array.java Two Pointers
986. Interval List Intersections LeetCode-986-Interval-List-Intersections.java Array, Intervals
★2031. Count Subarrays With More Ones Than Zeros LeetCode-2031-Count-Subarrays-With-More-Ones-Than-Zeros.java Array, MergeSort, BST, BIT, Segment Tree

|★78.Subsets|LeetCode-78-Subsets.java|DFS| |90.Subsets II|LeetCode-90-Subsets-II.java|DFS|

String

String includes Parentheness series, Palindrome series, Anagram series, some statistic problems.

回文串问题总结
LeetCode总结 —— Palindrome 回文总结
最长回文字符串、二重循环
「LeetCode」试题总结 - 回文数汇总

Question Solution Tags
3 Longest Substring Without Repeating Characters LeetCode-3-Longest-Substring-Without-Repeating-Characters.java Two Pointers
5.Longest Palindromic Substring LeetCode-5-Longest-Palindromic-Substring.java String
6 ZigZag Conversion LeetCode-6-ZigZag-Conversion.java String
8.String to Integer (atoi) LeetCode-8-String-to-Integer.java String
10. Regular Expression Matching LeetCode-10-Regular-Expression-Matching.java String
12.Integer to Roman LeetCode-12-Integer-to-Roman.java String
13.Roman to Integer LeetCode-13-Roman-to-Integer.java String
14 Longest Common Prefix LeetCode-14-Longest-Common-Prefix.java String
17.Letter Combinations of a Phone Number LeetCode-17-Letter-Combinations-of-a-Phone-Number.java DFS, BFS
★20.Valid Parentheses LeetCode-20-Valid-Parentheses.java HashMap, Stack
★22.Generate Parentheses LeetCode-22-Generate-Parentheses.java DFS, BFS
28.Implement strStr() LeetCode-28-Implement-strStr.java String, Two Pointers
★32. Longest Valid Parentheses LeetCode-32-Longest-Valid-Parentheses.java String, Stack, DP
38 Count and Say LeetCode-38-Count-and-Say.java String
44. Wildcard Matching LeetCode-44-Wildcard-Matching.java String
49.Group Anagrams LeetCode-49-Group-Anagrams.java String, HashMap
58.Length of Last Word LeetCode-58-Length-of-Last-Word.java String
65. Valid Number LeetCode-65-Valid-Number.java String
★68. Text Justification LeetCode-68-Text-Justification.java String
71.Simplify Path LeetCode-71-Simplify-Path.java String
★76. Minimum Window Substring LeetCode-76-Minimum-Window-Substring.java String
93.Restore IP Addresses LeetCode-93-Restore-IP-Addresses.java String, DFS
★125.Valid Palindrome LeetCode-125-Valid-Palindrome.java Two Pointers
★126.Word Ladder II LeetCode-126-Word-Ladder-II.java DFS+BFS
★127.Word Ladder LeetCode-127-Word-Ladder.java BFS
139.Word Break LeetCode-139-Word-Break.java DFS, DP
140.Word Break II LeetCode-140-Word-Break-II.java DP, Trie, Recursive
151.Reverse Words in a String LeetCode-151-Reverse-Words-in-a-String.java String
★157.Read N Characters Given Read4 LeetCode-157-Read-N-Characters-Given-Read4.java String
★158.Read N Characters Given Read4 II - Call multiple times LeetCode-158-Read-N-Characters-Given-Read4II-Call-multiple-times.java String
159. Longest Substring with At Most Two Distinct Characters LeetCode-159-Longest-Substring-with-At-Most-Two-Distinct-Characters.java String, SubString
161. One Edit Distance LeetCode-161-One-Edit-Distance.java String
165.Compare Version Numbers LeetCode-165-Compare-Version-Numbers.java String
179. Largest Number LeetCode-179-Largest-Number.java String
186.Reverse Words in a String II LeetCode-186-Reverse-Words-in-a-String-II.java String
249. Group Shifted Strings LeetCode-249-Group-Shifted-Strings.java String
273. Integer to English Words LeetCode-273-Integer-to-English-Words.java String
282. Expression Add Operators LeetCode-282-Expression-Add-Operators.java String
340. Longest Substring with At Most K Distinct Characters LeetCode-340-Longest-Substring-with-At-Most-K-Distinct-Characters.java String
344. Reverse String LeetCode-344-Reverse-String.java String
383. Ransom Note LeetCode-383-Ransom-Note.java String
387. First Unique Character in a String LeetCode-387-First-Unique-Character-in-a-String.java String
443. String Compression LeetCode-443-String-Compression.java String
468. Validate IP Address LeetCode-468-Validate-IP-Address.java String
557. Reverse Words in a String III LeetCode-557-Reverse-Words-in-a-String-III.java String
709. To Lower Case LeetCode-709-To-Lower-Case.java String
736. Parse Lisp Expression LeetCode-736-Parse-Lisp-Expression.java String
748. Shortest Completing Word LeetCode-748-Shortest-Completing-Word.java String
771. Jewels and Stones LeetCode-771-Jewels-and-Stones.java String
791. Custom Sort String LeetCode-791-Custom-Sort-String.java String
796. Rotate String LeetCode-796-Rotate-String.java String
804. Unique Morse Code Words LeetCode-804-Unique-Morse-Code-Words.java String
833. Find And Replace in String LeetCode-833-Find-And-Replace-in-String.java String
890. Find and Replace Pattern LeetCode-890-Find-and-Replace-Pattern.java String
929. Unique Email Addresses LeetCode-929-Unique-Email-Addresses.java String
937. Reorder Log Files LeetCode-937-Reorder-Log-Files.java String

|242.Valid Anagram|LeetCode-242-Valid-Anagram.java|Sort, Array Map| |32.Longest Valid Parentheses|LeetCode-32-Longest-Valid-Parentheses.java|Not Yet| |241.Different Ways to Add Parentheses|LeetCode-241.Different Ways to Add Parentheses.java|Not Yet| |9 Palindrome Number|LeetCode-9-Palindrome-Number.java|Math| |234.Palindrome Linked List|LeetCode-234-Palindrome-Linked-List.java|LinkedList| |131.Palindrome Partitioning|LeetCode-131-Palindrome-Partitioning.java|DFS| |★132.Palindrome Partitioning II|LeetCode-132-Palindrome-Partitioning-II.java|DP| |214.Shortest Palindrome|LeetCode-214-Shortest-Palindrome.java|Not Yet, Hard| |266.Palindrome Permutation|LeetCode-266-Palindrome-Permutation.java|HashMap| |267.Palindrome Permutation II|LeetCode-267-Palindrome-Permutation-II.java|Not Yet| |288.Unique Word Abbreviation|LeetCode-288-Unique-Word-Abbreviation.java|String|

|680. Valid Palindrome II|LeetCode-680-Valid-Palindrome-II.java|Not Yet|

Dynamic Programming

Question Solution Tags
★★★55.Jump Game LeetCode-55-Jump-Game.java DP, Greedy
45.Jump Game II LeetCode-45-Jump-Game-II.java DP, Greedy
★53.Maximum Subarray LeetCode-53-Maximum-Subarray.java DP, Greedy
Maximum Subarray II LintCode-Maximum-Subarray-II.java DP, Greedy
Maximum Subarray III LintCode-Maximum-Subarray-III.java not yet, hard
★62.Unique Paths LeetCode-62-Unique-Paths.java DP
63.Unique Paths II LeetCode-63-Unique-Paths-II.java DP
64.Minimum Path Sum LeetCode-64-Minimum-Path-Sum.java DP
70.Climbing Stairs LeetCode-70-Climbing-Stairs.java DP
72. Edit Distance LeetCode-72-Edit-Distance.java DP
91.Decode Ways LeetCode-91-Decode-Ways.java DP
97.Interleaving String LeetCode-97-Interleaving-String.java DP
★★★120.Triangle LeetCode-120-Triangle.java DP, Array
121.Best Time to Buy and Sell Stock LeetCode-121-Best-Time-to-Buy-and-Sell-Stock.java DP, Greedy
122.Best Time to Buy and Sell Stock II LeetCode-122-Best-Time-to-Buy-and-Sell-Stock-II.java Array
123.Best Time to Buy and Sell Stock III LeetCode-123-Best-Time-to-Buy-and-Sell-Stock-III.java hard,not yet???
188.Best Time to Buy and Sell Stock IV LeetCode-188-Best-Time-to-Buy-and-Sell-Stock-IV.java hard, not yet???
309.Best Time to Buy and Sell Stock with Cooldown LeetCode-309-Best-Time-to-Buy-and-Sell-Stock-with-Cooldown.java not yet???
135. Candy LeetCode-135-Candy.java Greedy
152. Maximum Product Subarray LeetCode-152-Maximum-Product-Subarray.java DP
★★★198. House Robber LeetCode-198-House-Robber.java DP
213. House Robber II LeetCode-213-House-Robber-II.java DP
★★★256. Paint House LeetCode-256-Paint-House.java DP
265. Paint House II LeetCode-265-Paint-House-II.java DP
★★★276. Paint Fence LeetCode-276-Paint-Fence.java DP
279. Perfect Squares LeetCode-279-Perfect-Squares.java DP
★★★300. Longest Increasing Subsequence LeetCode-300-Longest-Increasing-Subsequence.java DP, Binary Search
303. Range Sum Query - Immutable LeetCode-303-Range-Sum-Query-Immutable.java DP
304. Range Sum Query 2D - Immutable LeetCode-304-Range-Sum-Query-2D-Immutable.java DP
316. Remove Duplicate Letters LeetCode-316-Remove-Duplicate-Letters.java Greedy
★★★322. Coin Change LeetCode-322-Coin-Change.java DP
338. Counting Bits LeetCode-338-Counting-Bits.java DP, Math
375. Guess Number Higher or Lower II LeetCode-375-Guess-Number-Higher-or-Lower-II.java DP
377. Combination Sum IV LeetCode-377-Combination-Sum-IV.java DP
403. Frog Jump LeetCode-403-Frog-Jump.java DP
416. Partition Equal Subset Sum LeetCode-416-Partition-Equal-Subset-Sum.java DP
486. Predict the Winner LeetCode-486-Predict-the-Winner.java DP
★★★494. Target Sum LeetCode-494-Target-Sum.java DP
516. Longest Palindromic Subsequence LeetCode-516-Longest-Palindromic-Subsequence.java DP
★★★518. Coin Change 2 LeetCode-518-Coin-Change-2.java DP
605. Can Place Flowers LeetCode-605-Can-Place-Flowers.java Greedy
621. Task Scheduler LeetCode-621-Task-Scheduler.java Greedy
647. Palindromic Substrings LeetCode-647-Palindromic-Substrings.java DP
730. Count Different Palindromic Subsequences LeetCode-730-Count-Different-Palindromic-Subsequences.java DP
805. Split Array With Same Average LeetCode-805-Split-Array-With-Same-Average.java DP
968. Binary Tree Cameras LeetCode-968-Binary-Tree-Cameras.java DP, Greedy
★★★983. Minimum Cost For Tickets LeetCode-983-Minimum-Cost-For-Tickets.java DP
1049. Last Stone Weight II LeetCode-1049-Last-Stone-Weight-II.java DP
1094. Car Pooling LeetCode-1094-Car-Pooling.java DP

Tree Search(Tree, Binary Search, DFS, BFS)

Search in Tree, in Binary Tree, Binary Search Tree, in String, in Array
Search a required set, search Maximum/Minimu result

Tree大总结

  1. 求二叉树中的节点个数: getNodeNumRec(递归),getNodeNum(迭代)
  2. 求二叉树的深度: getDepthRec(递归),getDepth
  3. ★★★前序遍历,中序遍历,后序遍历: preorderTraversalRec, preorderTraversal, inorderTraversalRec, postorderTraversalRec
  4. ★★★分层遍历二叉树(按层次从上往下,从左往右):levelTraversal, levelTraversalRec(递归解法)
  5. 将二叉查找树变为有序的双向链表: convertBST2DLLRec, convertBST2DLL
  6. 求二叉树第K层的节点个数:getNodeNumKthLevelRec, getNodeNumKthLevel
  7. 求二叉树中叶子节点的个数:getNodeNumLeafRec, getNodeNumLeaf
  8. 判断两棵二叉树是否相同的树:isSameRec, isSame
  9. 判断二叉树是不是平衡二叉树:isAVLRec
  10. 求二叉树的镜像(破坏和不破坏原来的树两种情况):
    mirrorRec, mirrorCopyRec
    mirror, mirrorCopy
    10.1 判断两个树是否互相镜像:isMirrorRec isMirror
  11. 求二叉树中两个节点的最低公共祖先节点:
    LAC 求解最小公共祖先, 使用list来存储path
    LCABstRec 递归求解BST树
    LCARec 递归算法
  12. 求二叉树中节点的最大距离:getMaxDistanceRec
  13. 由前序遍历序列和中序遍历序列重建二叉树:rebuildBinaryTreeRec
  14. 判断二叉树是不是完全二叉树:isCompleteBinaryTree, isCompleteBinaryTreeRec
  15. 找出二叉树中最长连续子串(即全部往左的连续节点,或是全部往右的连续节点): findLongest

面试大总结之二:Java搞定面试中的二叉树题目
轻松搞定面试中的二叉树题目
算法大全(3)二叉树

Question Solution Tags
130.Surrounded Region LeetCode-130-Surrounded-Regions.java BFS,DFS
216.Combination Sum III LeetCode-216-Combination-Sum-III.java Not yet
77.Combinations LeetCode-77-Combinations.java DFS
278.First Bad Version LeetCode-278-First-Bad-Version.java Binary Search
205.Isomorphic Strings LeetCode-205-Isomorphic-Strings.java HashMap
290.Word Pattern LeetCode-290-Word-Pattern.java HashMap
291.Word Pattern II LeetCode-291-Word-Pattern-II.java Not yet, hard
94.Binary Tree Inorder Traversal LeetCode-94-Binary-Tree-Inorder-Traversal.java DFS, BFS
95.Unique Binary Search Trees II LeetCode-95-Unique-Binary-Search-Trees-II.java DFS
96.Unique Binary Search Trees LeetCode-96-Unique-Binary-Search-Trees.java DP
98.Validate Binary Search Tree LeetCode-98-Validate-Binary-Search-Tree.java DFS, BFS
99. Recover Binary Search Tree LeetCode-99-Recover-Binary-Search-Tree.java Traversal
100.Same Tree LeetCode-100-Same-Tree.java
101.Symmetric Tree LeetCode-101-Symmetric-Tree.java Recursive, Iterative
★102.Binary Tree Level Order Traversal I LeetCode-102-Binary-Tree-Level-Order-Traversal-I.java BFS, DFS
103.Binary Tree Zigzag Level Order Traversal LeetCode-103-Binary-Tree-Zigzag-Level-Order-Traversal.java BFS
104.Maximum Depth of Binary Tree LeetCode-104-Maximum-Depth-of-Binary-Tree.java DFS
105.Construct Binary Tree from Preorder and Inorder Traversal LeetCode-105-Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal.java DFS
106.Construct Binary Tree from Inorder and Postorder Traversal LeetCode-106-Construct-Binary-Tree-from-Inorder-and-Postorder-Traversal.java DFS
107.Binary Tree Level Order Traversal II LeetCode-107-Binary-Tree-Level-Order-Traversal-II.java BFS, DFS
108.Convert Sorted Array to Binary Search Tree LeetCode-108-Convert-Sorted-Array-to-Binary-Search-Tree.java DFS
109.Convert Sorted List to Binary Search Tree LeetCode-109-Convert-Sorted-List-to-Binary-Search-Tree.java DFS
110.Balanced Binary Tree LeetCode-110-Balanced-Binary-Tree.java DFS
111.Minimum Depth of Binary Tree LeetCode-111-Minimum-Depth-of-Binary-Tree.java DFS, BFS
★112.Path Sum LeetCode-112-Path-Sum.java DFS, BFS
113.Path Sum II LeetCode-113-Path-Sum-II.java DFS
114.Flatten Binary Tree to Linked List LeetCode-114-Flatten-Binary-Tree-to-Linked-List.java DFS
116.Populating Next Right Pointers in Each Node LeetCode-116-Populating-Next-Right-Pointers-in-Each-Node.java BFS, DFS
117.Populating Next Right Pointers in Each Node II LeetCode-117-Populating-Next-Right-Pointers-in-Each-Node-II.java BFS, DFS
124.Binary Tree Maximum Path Sum LeetCode-124-Binary-Tree-Maximum-Path-Sum.java DFS
129.Sum Root to Leaf Numbers LeetCode-129-Sum-Root-to-Leaf-Numbers.java DFS
144.Binary Tree Preorder Traversal LeetCode-144-Binary-Tree-Preorder-Traversal.java DFS, BFS
145.Binary Tree Postorder Traversal LeetCode-145-Binary-Tree-Postorder-Traversal.java DFS, BFS
156. Binary Tree Upside Down LeetCode-156-Binary-Tree-Upside-Down.java BFS, DFS
173. Binary Search Tree Iterator LeetCode-173-Binary-Search-Tree-Iterator.java BFS
199.Binary Tree Right Side View LeetCode-199-Binary-Tree-Right-Side-View.java BFS, DFS
222. Count Complete Tree Nodes LeetCode-222-Count-Complete-Tree-Nodes.java BFS, DFS
226. Invert Binary Tree LeetCode-226-Invert-Binary-Tree.java BFS, DFS
230. Kth Smallest Element in a BST LeetCode-230-Kth-Smallest-Element-in-a-BST.java BFS, DFS
235.Lowest Common Ancestor of a Binary Search Tree LeetCode-235-Lowest-Common-Ancestor-of-a-Binary-Search-Tree.java Tree, Recursive
236.Lowest Common Ancestor of a Binary Tree LeetCode-236-Lowest-Common-Ancestor-of-a-Binary-Tree.java Tree, Recursive
Search in a Big Sorted Array LintCode-Search-in-a-Big-Sorted-Array.java Binary Search
250. Count Univalue Subtrees LeetCode-250-Count-Univalue-Subtrees.java DFS
255. Verify Preorder Sequence in Binary Search Tree LeetCode-255-Verify-Preorder-Sequence-in-Binary-Search-Tree.java DFS
257.Binary Tree Paths LeetCode-257-Binary-Tree-Paths.java not yet
270.Closest Binary Search Tree Value LeetCode-270-Closest-Binary-Search-Tree-Value.java BFS, DFS, Traversal
272. Closest Binary Search Tree Value II LeetCode-272-Closest-Binary-Search-Tree-Value-II.java BFS, DFS, Traversal
285. Inorder Successor in BST LeetCode-285-Inorder-Successor-in-BST.java BFS
297. Serialize and Deserialize Binary Tree LeetCode-297-Serialize-and-Deserialize-Binary-Tree.java BFS, DFS
298. Binary Tree Longest Consecutive Sequence LeetCode-298-Binary-Tree-Longest-Consecutive-Sequence.java DFS
333. Largest BST Subtree LeetCode-333-Largest-BST-Subtree.java DFS
337. House Robber III LeetCode-337-House-Robber-III.java DFS
366. Find Leaves of Binary Tree LeetCode-366-Find-Leaves-of-Binary-Tree.java.java DFS
374. Guess Number Higher or Lower LeetCode-374-Guess-Number-Higher-or-Lower.java Binary Search
404. Sum of Left Leaves LeetCode-404-Sum-of-Left-Leaves.java DFS
427. Construct Quad Tree LeetCode-427-Construct-Quad-Tree.java Recursive
428. Serialize and Deserialize N-ary Tree LeetCode-428-Serialize-and-Deserialize-N-ary-Tree.java Recursive
437. Path Sum III LeetCode-437-Path-Sum-III.java DFS
450. Delete Node in a BST LeetCode-450-Delete-Node-in-a-BST.java DFS
501. Find Mode in Binary Search Tree LeetCode-501-Find-Mode-in-Binary-Search-Tree.java DFS
508. Most Frequent Subtree Sum LeetCode-508-Most-Frequent-Subtree-Sum.java DFS, similar to 501
510. Inorder Successor in BST II LeetCode-510-Inorder-Successor-in-BST-II.java DFS, similar to 285
513. Find Bottom Left Tree Value LeetCode-513-Find-Bottom-Left-Tree-Value.java DFS, BFS
515. Find Largest Value in Each Tree Row LeetCode-515-Find-Largest-Value-in-Each-Tree-Row.java DFS, BFS
530. Minimum Absolute Difference in BST LeetCode-530-Minimum-Absolute-Difference-in-BST.java DFS, BFS
538. Convert BST to Greater Tree LeetCode-538-Convert-BST-to-Greater-Tree.java inorder traversal
543. Diameter of Binary Tree LeetCode-543-Diameter-of-Binary-Tree.java DFS
545. Boundary of Binary Tree LeetCode-545-Boundary-of-Binary-Tree.java Recursive
582. Kill Process LeetCode-582-Kill-Process.java BFS, DFS
654. Maximum Binary Tree LeetCode-654-Maximum-Binary-Tree.java Recursive, Deque
655. Print Binary Tree LeetCode-655-Print-Binary-Tree.java BFS, DFS
662. Maximum Width of Binary Tree LeetCode-662-Maximum-Width-of-Binary-Tree.java Binary Tree, BFS
671. Second Minimum Node In a Binary Tree LeetCode-671-Second-Minimum-Node-In-a-Binary-Tree.java Recursive
701. Insert into a Binary Search Tree LeetCode-701-Insert-into-a-Binary-Search-Tree.java Recursive, Iterative
★863. All Nodes Distance K in Binary Tree LeetCode-863-All-Nodes-Distance-K-in-Binary-Tree.java Traversal, Convert Tree to Graph
958. Check Completeness of a Binary Tree LeetCode-958-Check-Completeness-of-a-Binary-Tree.java DFS
1382. Balance a Binary Search Tree LeetCode-1382-Balance-a-Binary-Search-Tree.java Tree
1644. Lowest Common Ancestor of a Binary Tree II LeetCode-1644-Lowest-Common-Ancestor-of-a-Binary-Tree-II.java DFS
1650. Lowest Common Ancestor of a Binary Tree III LeetCode-1650-Lowest-Common-Ancestor-of-a-Binary-Tree-III.java DFS
1676. Lowest Common Ancestor of a Binary Tree IV LeetCode-1676-Lowest-Common-Ancestor-of-a-Binary-Tree-IV.java DFS

DFS

Question Solution Tags
301.Remove Invalid Parentheses LeetCode-301-Remove-Invalid-Parentheses.java DFS, BFS, String
314.Binary Tree Vertical Order Traversal LeetCode-314-Binary-Tree-Vertical-Order-Traversal.java DFS, BFS, Traversal
987. Vertical Order Traversal of a Binary Tree LeetCode-987-Vertical-Order-Traversal-of-a-Binary-Tree.java DFS, BFS, Traversal

BFS

Question Solution Tags
317. Shortest Distance from All Buildings LeetCode-317-Shortest-Distance-from-All-Buildings.java BFS, Matrix
1091. Shortest Path in Binary Matrix LeetCode-1091-Shortest-Path-in-Binary-Matrix.java BFS, Matrix

List

Change Order(Reverse, Swap) & Remove
The use of dummy node, use pointer Next to store next node(Merge Two Sort Lists, Merge K Sorted Lists, Reverse List, Reverse Nodes in K-groups)
Find/Remove Kth biggest node from end: use two pointers, one run k step, and then two pointers run parallelly until one reach null. Find the middle of a list: fast-slow pointers, one run one step, another run two steps. Be carefully of initialization, slow = header, fast = header.next.(Find intersection point, Detect circle)

面试大总结之链表
轻松搞定面试中的链表题目
算法大全(1)单链表

Question Solution Tags
19.Remove Nth Node From End of List LeetCode-19-Remove-Nth-Node-From-End-of-List.java Two Pointers
21.Merge Two Sorted Lists LeetCode-21-Merge-Two-Sorted-Lists.java Recursive, Iterative
★23.Merge k Sorted Lists LeetCode-23-Merge-k-Sorted-Lists.java Merge Sort, Priority Queue
24.Swap Nodes in Pairs LeetCode-24-Swap-Nodes-in-Pairs.java LinkedList
25.Reverse Nodes in k-Group LeetCode-25-Reverse-Nodes-in-k-Group.java LinkedList
61 Rotate List LeetCode-61-Rotate-List.java Two Pointers
83.Remove Duplicates from Sorted List LeetCode-83-Remove-Duplicates-from-Sorted-List.java LinkedList
82.Remove Duplicates from Sorted List II LeetCode-82-Remove-Duplicates-from-Sorted-List-II.java LinkedList
86.Partition List LeetCode-86-Partition-List.java Two Pointers
92.Reverse Linked List II LeetCode-92-Reverse-Linked-List-II.java LinskedList
138. Copy List with Random Pointer LeetCode-138-Copy-List-with-Random-Pointer.java LinkedList
141.Linked List Cycle LeetCode-141-Linked-List-Cycle.java Two Pointers
142.Linked List Cycle II LeetCode-142-Linked-List-Cycle-II.java Two Pointers
143. Reorder List LeetCode-143-Reorder-List.java Two Pointers
147. Insertion Sort List LeetCode-147-Insertion-Sort-List.java Insertion Sort
148. Sort List LeetCode-148-Sort-List.java Merge Sort
160. Intersection of Two Linked Lists LeetCode-160-Intersection-of-Two-Linked-Lists.java Two Pointers
203.Remove Linked List Elements LeetCode-203-Remove-Linked-List-Elements.java LinkedList
206.Reverse Linked List LeetCode-206-Reverse-Linked-List.java LinskedList
237. Delete Node in a Linked List LeetCode-237-Delete-Node-in-a-Linked-List.java LinskedList

Trie

Question Solution Tags
208. Implement Trie (Prefix Tree) LeetCode-208-Implement-Trie-Prefix-Tree.java Trie
212. Word Search II LeetCode-212-Word-Search-II.java Trie
336. Palindrome Pairs LeetCode-336-Palindrome-Pairs.java Trie
720. Longest Word in Dictionary LeetCode-720-Longest-Word-in-Dictionary.java Trie

Heap or TreeMap

PriorityQueue.

Question Solution Tags
218. The Skyline Problem LeetCode-218-The-Skyline-Problem.java Heap, TreeMap
239. Sliding Window Maximum LeetCode-239-Sliding-Window-Maximum.java Heap, Deque
295. Find Median from Data Stream LeetCode-295-Find-Median-from-Data-Stream.java Heap
347. Top K Frequent Elements LeetCode-347-Top-K-Frequent-Elements.java Heap, Deque
373. Find K Pairs with Smallest Sums LeetCode-373-Find-K-Pairs-with-Smallest-Sums.java Heap
407. Trapping Rain Water II LeetCode-407-Trapping-Rain-Water-II.java Heap
451. Sort Characters By Frequency LeetCode-451-Sort-Characters-By-Frequency.java String, Heap, Bucket Sort
692. Top K Frequent Words LeetCode-692-Top-K-Frequent-Words.java Heap
729. My Calendar I LeetCode-729-My-Calendar-I.java TreeMap
973. K Closest Points to Origin LeetCode-973-K-Closest-Points-to-Origin.java Heap, QuickSelect
1046. Last Stone Weight LeetCode-1046-Last-Stone-Weight.java Max Heap

Graph

Question Solution Tags
133.Clone Graph LeetCode-133-Clone-Graph.java Graph, BFS, DFS
207. Course Schedule LeetCode-207-Course-Schedule.java Graph, Topological Sort
210. Course Schedule II LeetCode-210-Course-Schedule-II.java Graph, Topological Sort
269. Alien Dictionary LeetCode-269-Alien-Dictionary.java Graph, Topological Sort
785. Is Graph Bipartite? LeetCode-785-Is-Graph-Bipartite.java Graph, Topological Sort

Prefix Sum

Question Solution Tags
523. Continuous Subarray Sum LeetCode-523-Continuous-Subarray-Sum.java Prefix Sum, Array

Math

Prime
Operations between strings, between big numbers(larger than RAM: First external sorting (split into several parts), then K-way merge.)

Question Solution Tags
2.Add Two Numbers LeetCode-2-Add-Two-Numbers.java LinkedList
7.Reverse Integer LeetCode-7-Reverse-Integer.java Integer
43.Multiply Strings LeetCode-43-Multiply-Strings.java String
67.Add Binary LeetCode-67-Add-Binary.java String
29.Divide Two Integers LeetCode-29-Divide-Two-Integers.java Binary Search
50.Pow(x, n) LeetCode-50-Pow-n.java Binary Search
66.Plus One LeetCode-66-Plus-One.java Array
69.Sqrt(x) LeetCode-69-Sqrt-x.java Binary Search
89 Gray Code LeetCode-89-Gray-Code.java Math
149. Max Points on a Line LeetCode-149-Max-Points-on-a-Line.java Math
150. Evaluate Reverse Polish Notation LeetCode-150-Evaluate-Reverse-Polish-Notation.java Math
202. Happy Number LeetCode-202-Happy-Number.java Math
204.Count Primes LeetCode-204-Count-Primes.java Math
227. Basic Calculator II LeetCode-227-Basic-Calculator-II.java Math
233. Number of Digit One LeetCode-233-Number-of-Digit-One.java Math
254. Factor Combinations LeetCode-254-Factor-Combinations.java Recursive
311. Sparse Matrix Multiplication LeetCode-311-Sparse-Matrix-Multiplication.java Math
319. Bulb Switcher LeetCode-319-Bulb-Switcher.java Math
326. Power of Three LeetCode-326-Power-of-Three.java Math
367. Valid Perfect Square LeetCode-367-Valid-Perfect-Square.java Math, Binary Search
369. Plus One Linked List LeetCode-369-Plus-One-Linked-List.java Math
415. Add Strings LeetCode-415-Add-Strings.java Math
445. Add Two Numbers II LeetCode-445-Add-Two-Numbers-II.java LinkedList, Stack
479. Largest Palindrome Product LeetCode-479-Largest-Palindrome-Product.java Math
593. Valid Square LeetCode-593-Valid-Square.java Math
633. Sum of Square Numbers LeetCode-633-Sum-of-Square-Numbers.java Math
1017. Convert to Base -2 LeetCode-1017-Convert-to-Base--2.java Math
1073. Adding Two Negabinary Numbers LeetCode-1073-Adding-Two-Negabinary-Numbers.java Math

|60.Permutation Sequence|LeetCode-60-Permutation-Sequence.java|Math| |168.Excel Sheet Column Title|LeetCode-168-Excel-Sheet-Column-Title.java|Math| |171.Excel Sheet Column Number|LeetCode-171-Excel-Sheet-Column-Number.java|Math|

Bit Manipulation

Question Solution Tags
187. Repeated DNA Sequences LeetCode-187-Repeated-DNA-Sequences.java Bit Manipulation
190. Reverse Bits LeetCode-190-Reverse-Bits.java Bit Manipulation
191. Number of 1 Bits LeetCode-191-Number-of-1-Bits.java Bit Manipulation
201. Bitwise AND of Numbers Range LeetCode-201-Bitwise-AND-of-Numbers-Range.java Bit Manipulation
260.Single Number III LeetCode-260-Single-Number-III.java Bit Manipulation
318. Maximum Product of Word Lengths LeetCode-318-Maximum-Product-of-Word-Lengths.java Math
393. UTF-8 Validation LeetCode-393-UTF-8-Validation.java Math

Stack

https://leetcode.com/tag/stack/

Question Solution Tags
224. Basic Calculator LeetCode-224-Basic-Calculator.java Stack
394. Decode String LeetCode-394-Decode-String.java Stack
636. Exclusive Time of Functions LeetCode-636-Exclusive-Time-of-Functions.java Stack
946. Validate Stack Sequences LeetCode-946-Validate-Stack-Sequences.java Stack

Monotonic Stack

https://leetcode.com/tag/monotonic-stack/

Question Solution Tags
85. Maximal Rectangle LeetCode-85-Maximal-Rectangle.java Stack
1762. Buildings With an Ocean View LeetCode-1762-Buildings-With-an-Ocean-View.java Stack

Queue

https://leetcode.com/tag/queue/

Question Solution Tags
379. Design Phone Directory LeetCode-379-Design-Phone-Directory.java Queue

Union-Find

Question Solution Tags
128. Longest Consecutive Sequence LeetCode-128-Longest-Consecutive-Sequence.java Array, Union-Find
261. Graph Valid Tree LeetCode-261-Graph-Valid-Tree.java Graph, Union-Find, DFS, BFS
323. Number of Connected Components in an Undirected Graph LeetCode-323-Number-of-Connected-Components-in-an-Undirected-Graph.java Graph, Union-Find, DFS, BFS
547. Friend Circles LeetCode-547-Friend-Circles.java Union-Find, DFS

Reservoir Sampling

Question Solution Tags
382. Linked List Random Node LeetCode-382-Linked-List-Random-Node.java Reservoir Sampling

Segment Tree

Question Solution Tags
715. Range Module LeetCode-715-Range-Module.java Segment Tree, TreeMap

Design

Question Solution Tags
★146.LRU Cache LeetCode-146-LRU-Cache.java HashMap, List
155.Min Stack LeetCode-155-Min-Stack.java Two Stacks
225.Implement Stack using Queues LeetCode-225-Implement-Stack-using-Queues.java Queue
232.Implement Queue using Stacks LeetCode-232-Implement-Queue-using-Stacks.java Stack
251. Flatten 2D Vector LeetCode-251-Flatten-2D-Vector.java Two Pointers
281.Zigzag Iterator LeetCode-281-Zigzag-Iterator.java LinkedList
284.Peeking Iterator LeetCode-284-Peeking-Iterator.java Cache
346. Moving Average from Data Stream LeetCode-346-Moving-Average-from-Data-Stream.java LinkedList
348. Design Tic-Tac-Toe LeetCode-348-Design-Tic-Tac-Toe.java Array
353. Design Snake Game LeetCode-353-Design-Snake-Game.java Array
★362. Design Hit Counter LeetCode-362-Design-Hit-Counter.java Deque, Array
★380. Insert Delete GetRandom O(1) LeetCode-380-Insert-Delete-GetRandom-O(1).java LinkedList
381. Insert Delete GetRandom O(1) - Duplicates allowed LeetCode-381-Insert-Delete-GetRandomO(1)-Duplicates-allowed.java LinkedList
★432. All O one Data Structure LeetCode-432-All-O-one-Data-Structure.java HashMap, LinkedList
★460. LFU Cache LeetCode-460-LFU-Cache.java HashMap
535. Encode and Decode TinyURL LeetCode-535-Encode-and-Decode-TinyURL.java HashMap
706. Design HashMap LeetCode-706-Design-HashMap.java HashMap
716. Max Stack LeetCode-716-Max-Stack.java Two Stacks

173.Binary Search Tree Iterator

136.Single Number
137.Single Number II

30.Substring with Concatenation of All Words

/* LeetCode: LintCode: JiuZhang: ProgramCreek:

Analysis:

*/

地里2016年度所有Facebook面试题总结

Category
经典面试题总结 —— Binary Search 及其变种
BFS/DFS总结
转一些我blog上一些常见的二叉树面试问题和总结 (更新)

Here is a 10-line template that can solve most 'substring' problems

Backtracking Porblems总结(Subsets-Permutations-Combination-Sum-Palindrome-Partitioning)

O(N) template for Minimum Size Subarray Sum & Minimum Window Substring & Longest Substring Without Repeating Characters

刷题总结: http://joshuablog.herokuapp.com/Leetcode-%E6%80%BB%E7%BB%93.html

Reference

LeetCode | LintCode | JiuZhang
Top 10 Algorithms for Coding Interview
Top 10 algorithms in Interview Questions(G4G)
Simple Java Data Structure Summary

About

Repository of Coding Interview Questions, Data Structures

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages