Data Structures and Algorithms
Data structures, algorithms, and interview problems in Java.
Start with Big O and Time Complexity →Complexity Analysis
Big O, time and space complexity.
Arrays
Array and matrix problems.
- 3.Arrays in Java Interviews
- 4.Remove Even Integers From an Array
- 5.Merge Two Sorted Arrays
- 6.Find Two Numbers That Add Up to k
- 7.Product of Array Except Self
- 8.Find the Minimum Value in an Array
- 9.First Non-Repeating Integer in an Array
- 10.Find the Second Maximum Value in an Array
- 11.Rotate Array
- 12.Rearrange a Sorted Array in Max/Min Form
- 13.Maximum Subarray (Kadane's Algorithm)
- 14.Rotate a Matrix by 90 Degrees
- 15.Spiral Matrix
- 16.Sort an Array in Wave Form
- 17.Set Matrix Zeroes
- 18.Maximum j - i Such That a[j] > a[i]
- 19.Move Zeroes to the End
- 20.Container With Most Water
- 21.Remove Duplicates From a Sorted Array
- 22.Longest Common Prefix
Searching & Sorting
Binary search and sorting problems.
Linked Lists
Singly and doubly linked list problems.
- 29.Linked Lists in Java
- 30.Insertion at the Tail of a Linked List
- 31.Search in a Singly Linked List
- 32.Delete a Value From a Linked List
- 33.Find the Length of a Linked List
- 34.Reverse a Linked List
- 35.Detect a Cycle in a Linked List
- 36.Middle of the Linked List
- 37.Remove Duplicates From a Linked List
- 38.Union and Intersection of Linked Lists
- 39.Return the Nth Node From the End
- 40.Check if a Doubly Linked List Is a Palindrome
- 41.Swap Nodes in Pairs
- 42.Add Two Numbers Represented as Linked Lists
- 43.Reverse a Linked List From Position m to n
- 44.Detect and Remove a Loop in a Linked List
- 45.Merge Two Sorted Linked Lists
- 46.Sort a Linked List Using Insertion Sort
- 47.LRU Cache
Stacks
Stack problems.
Queues
Queue problems.
Heaps & Priority Queues
Heap and priority queue problems.
Hashing
HashMap and HashSet problems.
- 70.HashMap and HashSet in Java
- 71.Check if an Array Is a Subset of Another
- 72.Check if Two Arrays Are Disjoint
- 73.Find Symmetric Pairs in an Array
- 74.Trace the Complete Path of a Journey
- 75.Find Two Pairs Such That a + b = c + d
- 76.Find a Subarray With a Sum of 0
- 77.Word Formation Using a Hash Table
- 78.Find Two Numbers That Add Up to k (Hashing)
- 79.First Non-Repeating Integer (Hashing)
- 80.Linked List Cycle (Hashing)
- 81.Remove Duplicates From a Linked List (Hashing)
- 82.Union and Intersection of Linked Lists (Hashing)
- 83.Check if Two Arrays Are Equal
- 84.Intersection of Two Unsorted Arrays
- 85.Longest Consecutive Sequence
- 86.Valid Anagram
- 87.Majority Element
- 88.Sort Characters by Frequency
- 89.Triplets With a Sum of 0 (3Sum)
- 90.First Missing Positive
- 91.Largest Subarray With a Sum of 0
- 92.Max Points on a Line
Trees
Binary tree and BST problems.
- 93.Binary Trees and BSTs in Java
- 94.Find the Minimum Value in a BST
- 95.Find the kth Maximum Value in a BST
- 96.Find the Ancestors of a Node in a BST
- 97.Find the Height of a Binary Tree
- 98.Find Nodes at k Distance From the Root
- 99.Lowest Common Ancestor of a Binary Tree
- 100.Path Sum in a Binary Tree
- 101.Minimum Depth of a Binary Tree
- 102.Binary Tree Zigzag Level Order Traversal
- 103.Invert a Binary Tree
- 104.Flatten a Binary Tree to a Linked List
- 105.Diameter of a Binary Tree
- 106.All Nodes at Distance K in a Binary Tree
- 107.Merge Two Binary Trees
- 108.Convert a Sorted Array to a Balanced BST
- 109.Minimum Absolute Difference in a BST
- 110.Recover a Binary Search Tree
- 111.Merge Two BSTs Into a Sorted List
Graphs
Graph traversal, cycles, and shortest paths.
- 112.Graphs in Java
- 113.Implement Breadth-First Search
- 114.Implement Depth-First Search
- 115.Detect a Cycle in a Directed Graph
- 116.Course Schedule
- 117.Find a Mother Vertex in a Directed Graph
- 118.Count the Edges in an Undirected Graph
- 119.Check if a Path Exists Between Two Vertices
- 120.Graph Valid Tree
- 121.Find the Shortest Path Between Two Vertices
- 122.Remove an Edge From a Directed Graph
- 123.Word Ladder
- 124.Smallest Multiple Made of 0s and 1s
- 125.Check for a Loop in an Array of Jumps
- 126.Minimum Knight Moves on a Chessboard
- 127.Surrounded Regions
Tries
Prefix tree problems.
Math & Bit Manipulation
Number and bit manipulation problems.
Greedy Algorithms
Problems solved by taking the best choice at each step.
Backtracking
Build solutions step by step and undo wrong choices.
Dynamic Programming
Problems solved by reusing answers to smaller subproblems.
- 150.Climbing Stairs
- 151.Coin Change: Fewest Coins
- 152.Word Break
- 153.Minimum Cost Path in a Grid
- 154.Maximal Square
- 155.Maximum Product Subarray
- 156.Minimum Number of Jumps to Reach the End
- 157.Longest Increasing Subsequence
- 158.Longest Arithmetic Progression
- 159.Partition Equal Subset Sum
- 160.Edit Distance
- 161.Interleaving String
- 162.Palindrome Partitioning: Minimum Cuts
- 163.Matrix Chain Multiplication
Summary
Choosing a data structure, and interview tips.
