Guide contents

Data Structures and Algorithms

Data structures, algorithms, and interview problems in Java.

164 lessons in 16 sections

Start with Big O and Time Complexity →

Complexity Analysis

Big O, time and space complexity.

  1. 1.Big O and Time Complexity
  2. 2.Space Complexity and a Complexity Cheat Sheet

Arrays

Array and matrix problems.

  1. 3.Arrays in Java Interviews
  2. 4.Remove Even Integers From an Array
  3. 5.Merge Two Sorted Arrays
  4. 6.Find Two Numbers That Add Up to k
  5. 7.Product of Array Except Self
  6. 8.Find the Minimum Value in an Array
  7. 9.First Non-Repeating Integer in an Array
  8. 10.Find the Second Maximum Value in an Array
  9. 11.Rotate Array
  10. 12.Rearrange a Sorted Array in Max/Min Form
  11. 13.Maximum Subarray (Kadane's Algorithm)
  12. 14.Rotate a Matrix by 90 Degrees
  13. 15.Spiral Matrix
  14. 16.Sort an Array in Wave Form
  15. 17.Set Matrix Zeroes
  16. 18.Maximum j - i Such That a[j] > a[i]
  17. 19.Move Zeroes to the End
  18. 20.Container With Most Water
  19. 21.Remove Duplicates From a Sorted Array
  20. 22.Longest Common Prefix

Searching & Sorting

Binary search and sorting problems.

  1. 23.Search for a Range in a Sorted Array
  2. 24.Find the Minimum in a Sorted and Rotated Array
  3. 25.Find an Element in a Bitonic Array
  4. 26.Median of Two Sorted Arrays of the Same Size
  5. 27.Count Inversions in an Array
  6. 28.Median in a Row-Wise Sorted Matrix

Linked Lists

Singly and doubly linked list problems.

  1. 29.Linked Lists in Java
  2. 30.Insertion at the Tail of a Linked List
  3. 31.Search in a Singly Linked List
  4. 32.Delete a Value From a Linked List
  5. 33.Find the Length of a Linked List
  6. 34.Reverse a Linked List
  7. 35.Detect a Cycle in a Linked List
  8. 36.Middle of the Linked List
  9. 37.Remove Duplicates From a Linked List
  10. 38.Union and Intersection of Linked Lists
  11. 39.Return the Nth Node From the End
  12. 40.Check if a Doubly Linked List Is a Palindrome
  13. 41.Swap Nodes in Pairs
  14. 42.Add Two Numbers Represented as Linked Lists
  15. 43.Reverse a Linked List From Position m to n
  16. 44.Detect and Remove a Loop in a Linked List
  17. 45.Merge Two Sorted Linked Lists
  18. 46.Sort a Linked List Using Insertion Sort
  19. 47.LRU Cache

Stacks

Stack problems.

  1. 48.Stacks in Java
  2. 49.Implement Two Stacks Using One Array
  3. 50.Sort Values in a Stack
  4. 51.Evaluate a Postfix Expression
  5. 52.Next Greater Element
  6. 53.Valid Parentheses
  7. 54.Min Stack
  8. 55.Find the Celebrity
  9. 56.Trapping Rain Water
  10. 57.Merge Overlapping Intervals
  11. 58.Largest Rectangle in a Histogram

Queues

Queue problems.

  1. 59.Queues in Java
  2. 60.Generate Binary Numbers From 1 to n Using a Queue
  3. 61.Reverse the First k Elements of a Queue
  4. 62.Implement a Queue Using Stacks
  5. 63.Sliding Window Maximum

Heaps & Priority Queues

Heap and priority queue problems.

  1. 64.Heaps and PriorityQueue in Java
  2. 65.Convert a Max Heap to a Min Heap
  3. 66.Find the k Smallest Elements in an Array
  4. 67.Find the k Largest Elements in an Array
  5. 68.Find K Pairs With the Smallest Sums
  6. 69.Merge K Sorted Linked Lists

Hashing

HashMap and HashSet problems.

  1. 70.HashMap and HashSet in Java
  2. 71.Check if an Array Is a Subset of Another
  3. 72.Check if Two Arrays Are Disjoint
  4. 73.Find Symmetric Pairs in an Array
  5. 74.Trace the Complete Path of a Journey
  6. 75.Find Two Pairs Such That a + b = c + d
  7. 76.Find a Subarray With a Sum of 0
  8. 77.Word Formation Using a Hash Table
  9. 78.Find Two Numbers That Add Up to k (Hashing)
  10. 79.First Non-Repeating Integer (Hashing)
  11. 80.Linked List Cycle (Hashing)
  12. 81.Remove Duplicates From a Linked List (Hashing)
  13. 82.Union and Intersection of Linked Lists (Hashing)
  14. 83.Check if Two Arrays Are Equal
  15. 84.Intersection of Two Unsorted Arrays
  16. 85.Longest Consecutive Sequence
  17. 86.Valid Anagram
  18. 87.Majority Element
  19. 88.Sort Characters by Frequency
  20. 89.Triplets With a Sum of 0 (3Sum)
  21. 90.First Missing Positive
  22. 91.Largest Subarray With a Sum of 0
  23. 92.Max Points on a Line

Trees

Binary tree and BST problems.

  1. 93.Binary Trees and BSTs in Java
  2. 94.Find the Minimum Value in a BST
  3. 95.Find the kth Maximum Value in a BST
  4. 96.Find the Ancestors of a Node in a BST
  5. 97.Find the Height of a Binary Tree
  6. 98.Find Nodes at k Distance From the Root
  7. 99.Lowest Common Ancestor of a Binary Tree
  8. 100.Path Sum in a Binary Tree
  9. 101.Minimum Depth of a Binary Tree
  10. 102.Binary Tree Zigzag Level Order Traversal
  11. 103.Invert a Binary Tree
  12. 104.Flatten a Binary Tree to a Linked List
  13. 105.Diameter of a Binary Tree
  14. 106.All Nodes at Distance K in a Binary Tree
  15. 107.Merge Two Binary Trees
  16. 108.Convert a Sorted Array to a Balanced BST
  17. 109.Minimum Absolute Difference in a BST
  18. 110.Recover a Binary Search Tree
  19. 111.Merge Two BSTs Into a Sorted List

Graphs

Graph traversal, cycles, and shortest paths.

  1. 112.Graphs in Java
  2. 113.Implement Breadth-First Search
  3. 114.Implement Depth-First Search
  4. 115.Detect a Cycle in a Directed Graph
  5. 116.Course Schedule
  6. 117.Find a Mother Vertex in a Directed Graph
  7. 118.Count the Edges in an Undirected Graph
  8. 119.Check if a Path Exists Between Two Vertices
  9. 120.Graph Valid Tree
  10. 121.Find the Shortest Path Between Two Vertices
  11. 122.Remove an Edge From a Directed Graph
  12. 123.Word Ladder
  13. 124.Smallest Multiple Made of 0s and 1s
  14. 125.Check for a Loop in an Array of Jumps
  15. 126.Minimum Knight Moves on a Chessboard
  16. 127.Surrounded Regions

Tries

Prefix tree problems.

  1. 128.Tries in Java
  2. 129.Total Number of Words in a Trie
  3. 130.Find All Words Stored in a Trie
  4. 131.Sort an Array of Strings Using a Trie
  5. 132.Word Formation From a Dictionary Using a Trie
  6. 133.Shortest Unique Prefix of Every Word

Math & Bit Manipulation

Number and bit manipulation problems.

  1. 134.Roman to Integer
  2. 135.Reverse Bits
  3. 136.Square Root of an Integer
  4. 137.Calculate the Power Function
  5. 138.Greatest Common Divisor
  6. 139.Find the Closest Palindrome

Greedy Algorithms

Problems solved by taking the best choice at each step.

  1. 140.Maximum Product of Three Numbers
  2. 141.Gas Station
  3. 142.Distribute Candy
  4. 143.Fractional Knapsack

Backtracking

Build solutions step by step and undo wrong choices.

  1. 144.Generate Parentheses
  2. 145.Generate All Subsets
  3. 146.Combinations
  4. 147.Combination Sum
  5. 148.Letter Combinations of a Phone Number
  6. 149.Sudoku Solver

Dynamic Programming

Problems solved by reusing answers to smaller subproblems.

  1. 150.Climbing Stairs
  2. 151.Coin Change: Fewest Coins
  3. 152.Word Break
  4. 153.Minimum Cost Path in a Grid
  5. 154.Maximal Square
  6. 155.Maximum Product Subarray
  7. 156.Minimum Number of Jumps to Reach the End
  8. 157.Longest Increasing Subsequence
  9. 158.Longest Arithmetic Progression
  10. 159.Partition Equal Subset Sum
  11. 160.Edit Distance
  12. 161.Interleaving String
  13. 162.Palindrome Partitioning: Minimum Cuts
  14. 163.Matrix Chain Multiplication

Summary

Choosing a data structure, and interview tips.

  1. 164.Choosing a Data Structure and Interview Strategy