leetcode-top-interview-150

Leetcode Top Interview 150 Solutions

This repository contains a collection of Jupyter notebooks that provide solutions to various algorithmic problems. The problems are categorized based on their primary techniques or data structures used in the solutions.

Author of the Solutions

Rui Hu - github.com/logreg-n-coffee

Notes

The problems were originally developed by LeetCode. These solutions are provided for educational purposes.

Feel free to explore each notebook for detailed explanations and implementations of the solutions. Also, please don’t hesitate to submit an issue if you have any questions.

Table of Contents

  1. Array and String
  2. Two Pointers
  3. Sliding Window
  4. Matrix
  5. Hashmap
  6. Intervals
  7. Stack
  8. Linked List
  9. Binary Tree - General
  10. Binary Tree - BFS
  11. Graph - General
  12. Graph - BFS
  13. Trie
  14. Backtracking
  15. Divide and Conquer
  16. Kadane’s Algorithm
  17. Binary Search
  18. Heap
  19. Bit Manipulation
  20. Math
  21. 1D Dynamic Programming
  22. Multidimensional Dynamic Programming

Array and String

  1. Merge Sorted Array
  2. Remove Element
  3. Remove Duplicates from Sorted Array
  4. Remove Duplicates from Sorted Array II
  5. Majority Element
  6. Rotate Array
  7. Best Time to Buy and Sell Stock
  8. Best Time to Buy and Sell Stock II
  9. Jump Game
  10. Jump Game II
  11. H-Index
  12. Insert Delete Get Random O(1)
  13. Product of Array Except Self
  14. Gas Station
  15. Candy
  16. Trapping Rain Water
  17. Roman to Integer
  18. Integer to Roman
  19. Length of Last Word
  20. Longest Common Prefix
  21. Reverse Words in a String
  22. Zigzag Conversion
  23. Find the Index of the First Occurrence in a String
  24. Text Justification

Two Pointers

  1. Valid Palindrome
  2. Is Subsequence
  3. Container with Most Water
  4. Two Sum II - Input Array Is Sorted
  5. Three Sum
  6. Happy Number

Sliding Window

  1. Longest Substring Without Repeating Characters
  2. Minimum Window Substring
  3. Substring with Concatenation of All Words
  4. Minimum Size Subarray Sum

Matrix

  1. Valid Sudoku
  2. Spiral Matrix
  3. Rotate Image
  4. Set Matrix Zeroes
  5. Game of Life

Hashmap

  1. Ransom Note
  2. Isomorphic Strings
  3. Word Pattern
  4. Valid Anagram
  5. Group Anagrams
  6. Two Sum
  7. Contains Duplicate II
  8. Longest Consecutive Sequence

Intervals

  1. Summary Ranges
  2. Merge Intervals
  3. Insert Interval
  4. Minimum Number of Arrows to Burst Balloons

Stack

  1. Valid Parentheses
  2. Simplify Path
  3. Min Stack
  4. Evaluate Reverse Polish Notation
  5. Basic Calculator

Linked List

  1. Linked List Cycle
  2. Add Two Numbers
  3. Merge Two Sorted Lists
  4. Copy List with Random Pointer
  5. Reverse Linked List
  6. Reverse List in K Group
  7. Remove Nth Node from End of List
  8. Remove Duplicates from Sorted List II
  9. Rotate List
  10. Partition List
  11. LRU Cache

Binary Tree - General

  1. Maximum Depth of Binary Tree
  2. Same Tree
  3. Invert Binary Tree
  4. Symmetric Tree
  5. Construct Binary Tree from Preorder and Inorder Traversal
  6. Construct Binary Tree from Inorder and Postorder Traversal
  7. Populating Next Right Pointers in Each Node II
  8. Flatten Binary Tree to Linked List
  9. Path Sum
  10. Sum Root to Leaf Numbers
  11. Binary Tree Maximum Path Sum
  12. Binary Search Tree Iterator
  13. Count Complete Tree Nodes
  14. Lowest Common Ancestor of a Binary Tree

Binary Tree - BFS

  1. Binary Tree Right Side View
  2. Average of Levels in Binary Tree
  3. Binary Tree Level Order Traversal
  4. Binary Tree Zigzag Level Order Traversal
  5. Minimum Absolute Difference in BST
  6. Kth Smallest Element in BST
  7. Validate Binary Search Tree

Graph - General

  1. Number of Islands
  2. Surrounded Regions
  3. Clone Graph
  4. Evaluate Division
  5. Course Schedule
  6. Course Schedule II

Graph - BFS

  1. Snakes and Ladders
  2. Minimum Genetic Mutation
  3. Word Ladder

Trie

  1. Implement Trie (Prefix Tree)
  2. Design Add and Search Words Data Structure
  3. Word Search II

Backtracking

  1. Letter Combination of a Phone Number
  2. Combinations
  3. Permutations
  4. Combination Sum
  5. N-Queens II
  6. Generate Parentheses
  7. Word Search

Divide and Conquer

  1. Convert Sorted Array to Sorted Binary Search Tree
  2. Sort List
  3. Construct Quad Tree
  4. Merge K Sorted Lists

Kadane’s Algorithm

  1. Maximum Subarray
  2. Maximum Sum Circular Subarray
  1. Search Insert Position
  2. Search a 2D Matrix
  3. Find Peak Element
  4. Search in Rotated Sorted Array
  5. Find First and Last Position of Element in Sorted Array
  6. Find Minimum in Rotated Sorted Array
  7. Median of Two Sorted Arrays

Heap

  1. Kth Largest Element in an Array
  2. IPO
  3. Find K Pairs with Smallest Sums
  4. Find Median from Data Stream

Bit Manipulation

  1. Add Binary
  2. Reverse Bit
  3. Number of 1 Bits
  4. Single Number
  5. Single Number II
  6. Bitwise AND of Numbers Range

Math

  1. Palindrome Number
  2. Plus
  3. Factorial Trailing Zeroes
  4. Sqrt(x)
  5. Pow(x, n)
  6. Max Points on a Line

1D Dynamic Programming

  1. Climbing Stairs
  2. House Robber
  3. Word Break
  4. Coin Change
  5. Longest Increasing Subsequence

Multidimensional Dynamic Programming

  1. Triangle
  2. Minimum Path Sum
  3. Unique Path II
  4. Longest Palindromic Substring
  5. Interleaving String
  6. Edit Distance
  7. Best Time to Buy and Sell Stock III
  8. Best Time to Buy and Sell Stock IV
  9. Maximal Square