Algorithm Problem Classification

An algorithm problem contains 3 parts: the input, the output and the solution. The input data structures can be an array, string, tree, linked list, matrix, etc. The algorithm used to solve the problem can be dynamic programming, BFS and DFS. It can also be a data structure, such as a heap, stack, hash set, hash map, etc. In this post, the algorithm problems are classified by their input data structure. Under each categories, the problems are tagged with their algorithm or data structure used to solve the problem.

1. Array/String

--Two Pointers--
1) Two Sum, Two Sum II, Two Sum III, 3Sum, 4Sum, 3Sum Closest
2) Minimum Size Subarray Sum, Maximum Size Subarray Sum Equals k
3) Remove Duplicates from Sorted Array I, II, Remove Element , Move Zeroes
4) Container With Most Water, Candy , Trapping Rain Water
5) Summary Ranges
6) One Edit Distance
7) Merge Sorted Array
8) Shortest Word Distance, Shortest Word Distance II, Shortest Word Distance III
9) Intersection of Two Arrays, Intersection of Two Arrays II
10) Product of Array Except Self
11) Is Subsequence
12) Binary Watch
13) Reverse Vowels of a String

--classic array problem--
Kth Largest Element in an Array
Remove K Digits
Queue Reconstruction by Height (using index to add elements to a list)

--Finding a Number--
Missing Number
Find the duplicate number
First Missing Positive

--Binary Search--
Median of Two Sorted Arrays
Search Insert Position
Find Minimum in Rotated Sorted Array: I, II
Search for a Range
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

Evaluate Reverse Polish Notation (Stack)
Valid Parentheses
Longest Valid Parentheses
Valid Palindrome
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

Valid Anagram, Group Shifted Strings
Palindrome Pairs
Line Reflection

Longest Substring Without Repeating Characters
Longest Substring that contains 2 unique characters [Google]
Substring with Concatenation of All Words
Minimum Window Substring
Longest Substring with At Least K Repeating Characters

Isomorphic Strings
Longest Consecutive Sequence

Majority Element: I, II
Increasing Triplet Subsequence, Find Top 2 Largest Elements

Rotate Array, Reverse Words in a String

--Bucket Sort--
Group Anagrams

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

Word Ladder (BFS), Word Ladder II (BFS)

Top K Frequent Elements
Meeting Rooms II, Meeting Rooms
Range Addition
Merge k sorted arrays
Merge k Sorted Lists
Rearrange String k Distance Apart

Contains Duplicate: I, II, III
Max Sum of Rectangle No Larger Than K
Maximum Sum Of Subarray Close To K

--Track min/max and update result--
H-Index , H-Index II

Sliding Window Maximum
Moving Average from Data Stream
Find Median from Data Stream
Data Stream as Disjoint Intervals

Largest Number
Insertion Sort.
Maximum Gap (Bucket Sort)
Sort Colors (Counting Sort)

Merge Intervals
Insert Interval

--Implement data structure--
Implement a Stack Using an Array
Implement Stack using Queues
Implement Queue using Stacks
Implement a Queue using an Array

Implement Trie (Prefix Tree)
Add and Search Word - Data structure design (DFS)

--Segment Tree & Binary Index Tree--
Range Sum Query - Mutable
The Skyline Problem

--Graph--(mainly topological sort)--
Clone Graph
Course Schedule , Course Schedule II , Minimum Height Trees
Reconstruct Itinerary
Graph Valid Tree

--Ugly Number--
Ugly Number, Ugly Number II
Super Ugly Number
Find K Pairs with Smallest Sums

--Maximum subarray--
Maximum Subarray
Maximum Product Subarray

--Word break--
Word Break
Word Break II

Palindrome Partitioning
Palindrome Partitioning II
House Robber, II, III
Jump Game, II
Best Time to Buy and Sell Stock , II, III , IV
Dungeon Game
Minimum Path Sum
Unique Paths
Decode Ways
Coin Change
Perfect Squares

Edit Distance
Distinct Subsequences Total
Longest Palindromic Substring
Longest Common Subsequence
Longest Common Substring

--Design data structure with time requirements--
LRU Cache
Insert Delete GetRandom O(1)
Insert Delete GetRandom O(1) - Duplicates allowed
Insert Delete GetMostFrequent O(1)
Design Phone Directory
Design Twitter

--Other dbf/bfs--
Permutations II
Permutation Sequence
Generate Parentheses
Combination Sum (DFS), II (DFS), III (DFS), IV (DP)
Combinations (DFS)
Letter Combinations of a Phone Number (DFS)
Restore IP Addresses
Factor Combinations (DFS)
Subsets II

Linked List Random Node
Shuffle an Array

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
Reverse Vowels of a String
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

2. Matrix

--sorted matrix--
Search a 2D Matrix
Search a 2D Matrix II
Kth Smallest Element in a Sorted Matrix

Design Snake Game

Set Matrix Zeroes
Spiral Matrix
Spiral Matrix II
Rotate Image [Palantir]
Minimum Path Sum (DP)
Unique Paths (DP)
Unique Paths II (DP)
Number of Islands (DFS/BFS), Number of Islands II (Disjoint Set), Number of Connected Components in an Undirected Graph
Surrounded Regions (BFS)
Maximal Square
Word Search (DFS)
Word Search II
Range Sum Query 2D – Immutable
Longest Increasing Path in a Matrix (DFS)
Shortest Distance from All Buildings
Game of Life
Paint House, Paint House II
Sudoku Solver (DFS), Valid Sudoku
Walls and Gates (DFS/BFS)
Best Meeting Point
Find a Path in a Matrix

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, 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

Binary Tree Traversal: Preorder, Inorder, Postorder, Level Order, Level Order II, Vertical Order


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
1Lowest Common Ancestor of a Binary Tree
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

5. 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

6. Math

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

Category >> Algorithms  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";
  • srinidhi ram

    super .thanks a lot