An algorithm problem contains 3 parts: input, output and solution/algorithm. The input can be an array, string, matrix, tree, linked list, graph, etc. The algorithm solution can be dynamic programming, binary search, BFS, DFS, or topological sort. The solution can also be a data structure, such as a stack, queue/dequeue, hash set, tree set, hash map, tree (heap, binary search tree, trie, segment tree, binary index tree), disjoint set, etc. In this post, problems are tagged by input data structures or algorithms.
1. Array/String
–Simple Pointers–
1) Remove Duplicates from Sorted Array I, II, Remove Element, Move Zeroes
2) Candy, Trapping Rain Water, Product of Array Except Self
3) Minimum Size Subarray Sum, Summary Ranges, Missing Ranges
4) Merge Intervals, Insert Interval, Partition Labels, Find And Replace in String, My Calendar II
5) One Edit Distance, Merge Sorted Array, Is Subsequence, Backspace String Compare, Repeated String Match
6) Container With Most Water, Reverse Vowels of a String, Valid Palindrome
7) Shortest Word Distance, Shortest Word Distance II, Shortest Word Distance III
8) Intersection of Two Arrays, Intersection of Two Arrays II
9) Two Sum II, Two Sum III, 3Sum, 4Sum, 3Sum Closest
10) Wiggle Sort, Wiggle subsequence
11) Longest Common Prefix
12) Next permutation, Sentence Screen Fitting
–Binary Search–
Search Insert Position
Median of Two Sorted Arrays
Find Minimum in Rotated Sorted Array: I, II
Find First and Last Position of Element in Sorted Array
Guess Number Higher or Lower
First Bad Version
Search in Rotated Array:I, II
Longest Increasing Subsequence, Count of Smaller Numbers After Self
Russian Doll Envelopes
H-Index, H-Index II
–HashMap–
Valid Anagram, Group Shifted Strings
Palindrome Pairs
Line Reflection
Isomorphic Strings
–Sum subarray related problems–
Two Sum, Maximum Size Subarray Sum Equals k, Subarray Sum Equals K
–HashMap–Tracking–
Longest Substring Without Repeating Characters
Longest Substring that contains k unique characters
Substring with Concatenation of All Words
Minimum Window Substring
Longest Substring with At Least K Repeating Characters
Permutation in String
–HashSet–
Longest Consecutive Sequence
–Caching–
Majority Element: I, II
Increasing Triplet Subsequence, Find the 2nd Largest Elements in an array
–BFS–
Word Ladder (BFS), Word Ladder II (BFS)
–Heap–
Top K Frequent Elements
Meeting Rooms II, Meeting Rooms
Range Addition
Merge k sorted arrays
Merge k Sorted Lists
Rearrange String k Distance Apart
Minimum Cost to Hire K Workers
How does a heap work? a short video
–TreeSet–
Contains Duplicate: I, II, III
Max Sum of Rectangle No Larger Than K
Maximum Sum Of Subarray Close To K
K Empty Slots
–Stream–(deque/caching/heap/treeset)
Sliding Window Maximum
Moving Average from Data Stream
Find Median from Data Stream
Data Stream as Disjoint Intervals
Streaming random: Linked List Random Node, Shuffle an Array
–Sorting–
Mergesort
Quicksort, Kth Largest Element in an Array
Sort Colors (Counting Sort)
Maximum Gap (Bucket Sort)
Group Anagrams (Bucket Sort)
–tracking index using an array–
Ugly Number, Ugly Number II
Super Ugly Number
Find K Pairs with Smallest Sums from two arrays
–Rotate–
Rotate Array, Reverse Words in a String
–Finding a Number–
Missing Number
Find the duplicate number
First Missing Positive
–using index to add elements to a list–
Queue Reconstruction by Height
–Iterate within a boundary if the boundary is fixed–
Binary Watch
Next Closest Time
2. Matrix
–sorted matrix–
Search a 2D Matrix
Search a 2D Matrix II
Kth Smallest Element in a Sorted Matrix
–queue–
Design Snake Game
–union-find (disjoint set)–
Number of Islands II
Number of Connected Components in an Undirected Graph
Most Stones Removed with Same Row or Column
–DFS–
Longest Increasing Path in a Matrix
Word Search, Word Search II
Number of Islands (DFS/BFS)
Find a Path in a Matrix
Sudoku Solver, Valid Sudoku
Walls and Gates (DFS/BFS)
–BFS–
Surrounded Regions (BFS)
–Others–
Set Matrix Zeroes
Spiral Matrix, Spiral Matrix II
Rotate Image
Range Sum Query 2D – Immutable
Shortest Distance from All Buildings, Best Meeting Point
Game of Life
Tic-Tac-Toe
–matrix multiplication–
Sparse Matrix Multiplication
3. Linked List
Add Two Numbers
Reorder List
Linked List Cycle
Copy List with Random Pointer
Merge Two Sorted Lists
Odd Even Linked List
Remove Duplicates from Sorted List
Remove Duplicates from Sorted List II
Partition List
Intersection of Two Linked Lists
Remove Linked List Elements
Swap Nodes in Pairs
Reverse Linked List, Reverse Linked List II, Reverse Double Linked List, Print Linked List in Reversed Order
Remove Nth Node From End of List (Fast-Slow Pointers)
Palindrome Linked List
Delete Node in a Linked List
Reverse Nodes in k-Group
Sort List
Plus One Linked List
4. Tree
–traveral–
Binary Tree Traversal: Preorder, Inorder, Postorder, Level Order, Level Order II, Vertical Order
–dfs/bfs–
Invert Binary Tree
Kth Smallest Element in a BST
Binary Tree Longest Consecutive Sequence
Validate Binary Search Tree
Flatten Binary Tree to Linked List
Path Sum (DFS or BFS)
Path Sum II (DFS)
Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Preorder and Inorder Traversal
Convert Sorted Array to Binary Search Tree
Convert Sorted List to Binary Search Tree
Minimum Depth of Binary Tree
Binary Tree Maximum Path Sum *
Balanced Binary Tree
Symmetric Tree
Binary Search Tree Iterator
Binary Tree Right Side View
Lowest Common Ancestor of a Binary Search Tree
Lowest Common Ancestor of a Binary Tree
Most Frequent Subtree Sum
Verify Preorder Serialization of a Binary Tree
Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each Node II
Unique Binary Search Trees (DP)
Unique Binary Search Trees II (DFS)
Sum Root to Leaf Numbers (DFS)
Count Complete Tree Nodes
Closest Binary Search Tree Value
Binary Tree Paths
Maximum Depth of Binary Tree
Recover Binary Search Tree
Same Tree
Serialize and Deserialize Binary Tree
Inorder Successor in BST, Inorder Successor in BST II
Find Leaves of Binary Tree
Largest BST Subtree
Convert BST to Sorted Doubly Linked List
–Trie–
Implement Trie (Prefix Tree)
Add and Search Word – Data structure design (DFS)
–Segment Tree & Binary Index Tree–
Range Sum Query – Mutable
The Skyline Problem
5. Stack
–Stack and Queue data structure implementation (get familiar with stack and queue)–
Implement Stack using Queues
Implement Queue using Stacks
Implement a Stack Using an Array
Implement a Queue using an Array
–Stack–
Evaluate Reverse Polish Notation (Stack)
Valid Parentheses
Longest Valid Parentheses
Min Stack
Max Chunks To Make Sorted
–Stack–Largest Rectangle–
Largest Rectangle in Histogram
Maximal Rectangle
–Stack–Nested Object–
Mini Parser
Flatten Nested List Iterator
Nested List Weight Sum
Nested List Weight Sum II (HashMap)
Longest Absolute File Path
Decode String
Evaluate Math Expression
6. DFS
Partition to K Equal Sum Subsets
Permutations, Permutations II, Permutation Sequence, Number of Squareful Arrays
Generate Parentheses
Combination Sum (DFS), II (DFS), III (DFS), IV (DP)
Wildcard Matching, Regular Expression Matching, Expressive Words
Get Target Using Number List And Arithmetic Operations
Flip Game, Flip Game II
Word Pattern, Word Pattern II
Scramble String
Remove Invalid Parentheses
Shortest Palindrome
Lexicographical Numbers
Combinations (DFS)
Letter Combinations of a Phone Number (DFS)
Restore IP Addresses
Factor Combinations (DFS)
Subsets, Subsets II
7. Dynamic Programming
Coin Change
Palindrome Partitioning
Palindrome Partitioning II
House Robber, II, III
Jump Game, II
Best Time to Buy and Sell Stock , II, III , IV
Dungeon Game
Decode Ways
Perfect Squares
Word Break
Word Break II
Minimum Window Subsequence
Maximal Square
Minimum Path Sum
Unique Paths
Unique Paths II
Paint House, Paint House II
Maximum Subarray
Maximum Product Subarray
–DP–2D–
Edit Distance
Distinct Subsequences Total
Longest Palindromic Substring
Longest Common Subsequence
Longest Common Substring
8. Data Structure Design
LRU Cache
Insert Delete GetRandom O(1)
Insert Delete GetRandom O(1) – Duplicates allowed
Insert Delete GetMostFrequent O(1)
Design Phone Directory
Design Twitter
9. Bit Manipulation
Single Number
Single Number II
Maximum Binary Gap
Number of 1 Bits
Reverse Bits
Repeated DNA Sequences
Bitwise AND of Numbers Range
Sum of Two Integers
Counting Bits
Maximum Product of Word Lengths
Gray Code
UTF-8 Validation
10. Graph
—-topological sort—-
Course Schedule
Course Schedule II
Minimum Height Trees
—-BFS/DFS—-
Graph Valid Tree
Clone Graph
Reconstruct Itinerary
11. Math/Numbers
–power–
Pow(x,n), Power of Two, Power of Three, Power of Four
Super Pow
–/%–
Reverse Integer
Palindrome Number
Nth Digit
Fraction to Recurring Decimal
Excel Sheet Column Number
Excel Sheet Column Title
Factorial Trailing Zeroes
Happy Number
Count Primes
Plus One
Divide Two Integers
Multiply Strings
Max Points on a Line
Integer Break
Add Digits
Largest Divisible Subset
Count Numbers with Unique Digits
Rotated Digits
Remove K Digits
–Other–
Largest Number
Triangle
String to Integer
Implement strStr()
ZigZag Conversion
Add Binary
Length of Last Word
Bulls and Cows
Simplify Path
Compare Version Numbers
Pascal’s Triangle: I, II
Count and Say
Basic Calculator, Basic Calculator II
Rectangle Area
Find Peak Element
Integer to English Words
Text Justification
Gas Station
Self Crossing
Patching Array
Nim Game (List first few examples and find rules)
Bulb Switcher
Pain Fence
Nested List Weight Sum
Thank u
https://media0.giphy.com/media/LRORznnSGSNYqjUxUf/giphy.gif
super .thanks a lot