Algorithm Problem Classification
A typical process of solving an algorithm problem includes the following:
 Understand the problem (mainly the input and the output) and ask clarification questions
 Use an example to visualize how an algorithm is expected to work
 Come up with potential solutions and explain them to the interviewer(from highlevel to details)
 Write the code
Visualization is the key of solving a problem. It not only helps understand and clarify the problem, but also helps us come up with a solution. A proper visualization with an example often leads to a solution. In addition, visualization is an easy way to explain the thoughts to the interviewer.
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 classified by their input data structures. Under each categories, the problems are tagged with their algorithm or data structure.
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, Merge Intervals, Insert Interval
4) One Edit Distance, Merge Sorted Array, Is Subsequence
5) Container With Most Water, Reverse Vowels of a String
6) Shortest Word Distance, Shortest Word Distance II, Shortest Word Distance III
7) Intersection of Two Arrays, Intersection of Two Arrays II
8) Two Sum II, Two Sum III, 3Sum, 4Sum, 3Sum Closest
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
HashMap
Valid Anagram, Group Shifted Strings
Palindrome Pairs
Line Reflection
Sum subarray related problems
Two Sum, Maximum Size Subarray Sum Equals k, Subarray Sum Equals K
Maximum Subarray
Maximum Product Subarray
HashMapTracking
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
HashSet
Isomorphic Strings
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
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
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
Insertion Sort.
Sort Colors (Counting Sort)
Maximum Gap (Bucket Sort)
Group Anagrams (Bucket Sort)
Graph(mainly topological sort)
Clone Graph
Course Schedule, Course Schedule II, Minimum Height Trees
Reconstruct Itinerary
Graph Valid Tree
tracking index using an array
Ugly Number, Ugly Number II
Super Ugly Number
Find K Pairs with Smallest Sums from two arrays
Track min/max and update result
HIndex, HIndex II
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
2. Matrix
sorted matrix
Search a 2D Matrix
Search a 2D Matrix II
Kth Smallest Element in a Sorted Matrix
queue
Design Snake Game
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)
DFS/BFS
Set Matrix Zeroes
Spiral Matrix
Spiral Matrix II
Rotate Image
Surrounded Regions (BFS)
Range Sum Query 2D – Immutable
Shortest Distance from All Buildings
Game of Life
TicTacToe
Best Meeting Point
matrix multiplication
Sparse Matrix Multiplication
unionfind (disjoint set)
Number of Islands II (Disjoint Set), Number of Connected Components in an Undirected Graph
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, Print Linked List in Reversed Order
Remove Nth Node From End of List (FastSlow Pointers)
Palindrome Linked List
Delete Node in a Linked List
Reverse Nodes in kGroup
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
Find Leaves of Binary Tree
Largest BST Subtree
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
Valid Palindrome
Min Stack
Max Chunks To Make Sorted
StackLargest Rectangle
Largest Rectangle in Histogram
Maximal Rectangle
StackNested Object
Mini Parser
Flatten Nested List Iterator
Nested List Weight Sum
Nested List Weight Sum II (HashMap)
Longest Absolute File Path
Decode String
6. DFS
Partition to K Equal Sum Subsets
Permutations, Permutations II, Permutation Sequence
Generate Parentheses
Combination Sum (DFS), II (DFS), III (DFS), IV (DP)
Wildcard Matching, Regular Expression Matching
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
DP2D
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
UTF8 Validation
10. 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
Longest Common Prefix
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
<pre><code> String foo = "bar"; </code></pre>

srinidhi ram