Hi π, I'm Chee Hwa and welcome to LeetCode Solutions in Java.
As I'm new to LeetCode and programming in general, I'm practicing everyday and hope to share my solutions and learnings with you.
- Exclusively on Java
- Beginner problems
- Daily Challenge if within my ability
Date | Problem | Difficulty | Solution | Topics |
---|---|---|---|---|
September 14th | 1775. Equal Sum Arrays With Minimum Number of Operations | Counting | Array, Counting, Greedy | |
September 13th | 1814. Count Nice Pairs in an Array | Counting & Hash Table | Array, Counting, Hash Table, Math | |
September 12th | 2006. Count Number of Pairs With Absolute Difference K | Hash Table | Array, Hash Table | |
September 11th | 2006. Count Number of Pairs With Absolute Difference K | Counting | Array, Counting | |
September 10th | 2006. Count Number of Pairs With Absolute Difference K | Brute Force | Array |
The problem sets and solutions are grouped into Topics as stated in LeetCode.
- Array
- Backtracking
- Binary Search
- Binary Search Tree
- Binary Tree
- Bit Manipulation
- Brainteaser
- Breadth-First Search
- Bucket Sort
- Counting
- Counting Sort
- Data Stream
- Depth-First Search
- Design
- Divide and Conquer
- Dynamic Programming
- Enumeration
- Geometry
- Graph
- Greedy
- Hash Table
- Heap (Priority Queue)
- Interactive
- Linked List
- Math
- Matrix
- Memoization
- Monotonic Stack
- Number Theory
- Ordered Set
- Prefix Sum
- Queue
- Recursion
- Simulation
- Sliding Window
- Sorting
- Stack
- String
- Tree
- Two Pointers
- Union Find
Array
Backtracking
Binary Search
Binary Search Tree
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
98 | Validate Binary Search Tree | Java with Depth-First Search (Iterative) or Depth-First Search (Recursive) | Binary Search Tree, Binary Tree, Depth-First Search, Tree | ||
653 | Two Sum IV - Input is a BST | Java with Breadth-First Search (with Hash Table), Breadth-First Search (without Hash Table), Depth-First Search (Iterative), Depth-First Search (Recursive), Two Pointers (with Iterative Inorder Traversal) or Two Pointers (with Recursive Inorder Traversal) | Binary Search Tree, Binary Tree, Breadth-First Search, Depth-First Search, Hash Table, Tree, Two Pointers | ||
783 | Minimum Distance Between BST Nodes | Java with Breadth-First Search, Depth-First Search (Iterative) or Depth-First Search (Recursive) | Binary Search Tree, Binary Tree, Breadth-First Search, Depth-First Search, Tree |
Binary Tree
Bit Manipulation
Brainteaser
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
1033 | Moving Stones Until Consecutive | Java | Brainteaser, Math |
Breadth-First Search
Bucket Sort
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
220 | Contains Duplicate III | Java with Sliding Window & Bucket Sort | Array, Bucket Sort, Ordered Set, Sliding Window, Sorting | Solution Using Sliding Window & Ordered Set or Sorting |
Counting
Counting Sort
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
274 | H-Index | Java | Array, Counting Sort, Sorting | Solution Using Sorting | |
561 | Array Partition | Java | Array, Counting Sort, Greedy, Sorting | Solution Using Greedy & Sorting | |
1051 | Height Checker | Java | Array, Counting Sort, Sorting | Solution Using Sorting | |
1122 | Relative Sort Array | Java | Array, Counting Sort, Hash Table, Sorting | Solution Using Hash Table |
Data Stream
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
295 | Find Median from Data Stream | Java | Data Stream, Design, Heap (Priority Queue), Sorting, Two Pointers |
Depth-First Search
Design
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
225 | Implement Stack using Queues | Java | Design, Queue, Stack | ||
232 | Implement Queue using Stacks | Java | Design, Queue, Stack | ||
295 | Find Median from Data Stream | Java | Data Stream, Design, Heap (Priority Queue), Sorting, Two Pointers | ||
707 | Design Linked List | Java with Singly Linked List or Doubly Linked List | Design, Linked List | ||
1603 | Design Parking System | Java | Counting, Design, Simulation | ||
1865 | Finding Pairs With a Certain Sum | Java | Array, Design, Hash Table |
Divide and Conquer
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
169 | Majority Element | Java | Array, Counting, Divide and Conquer, Hash Table, Sorting | Solution Using Boyer-Moore Majority Voting Algorithm, Counting & Hash Table or Sorting |
Dynamic Programming
Enumeration
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
1534 | Count Good Triplets | Java | Array, Enumeration | ||
1995 | Count Special Quadruplets | Java | Array, Enumeration | Solution Using Hash Table | |
2240 | Number of Ways to Buy Pens and Pencils | Java | Enumeration, Math | ||
2437 | Number of Valid Clock Times | Java | Enumeration, String |
Geometry
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
223 | Rectangle Area | Java | Geometry, Math | ||
593 | Valid Square | Java | Geometry, Math | ||
812 | Largest Triangle Area | Java | Array, Geometry, Math | ||
836 | Rectangle Overlap | Java | Geometry, Math | ||
1037 | Valid Boomerang | Java | Array, Geometry, Math | ||
1232 | Check If It Is a Straight Line | Java | Array, Geometry, Math |
Graph
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
797 | All Paths From Source to Target | Java with Breadth-First Search, Depth-First Search (Backtracking), Depth-First Search (Iterative) or Depth-First Search (Recursive) | Backtracking, Breadth-First Search, Depth-First Search, Graph | ||
1971 | Find if Path Exists in Graph | Java with Breadth-First Search, Depth-First Search (Iterative), Depth-First Search (Recursive) or Union Find | Breadth-First Search, Depth-First Search, Graph, Union Find | ||
2359 | Find Closest Node to Given Two Nodes | Java | Depth-First Search, Graph |
Greedy
Hash Table
Heap (Priority Queue)
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
264 | Ugly Number II | Java | Dynamic Programming, Hash Table, Heap (Priority Queue), Math | Solution Using Dynamic Programming | |
295 | Find Median from Data Stream | Java | Data Stream, Design, Heap (Priority Queue), Sorting, Two Pointers | ||
1337 | The K Weakest Rows in a Matrix | Java with Heap (Priority Queue) & Binary Search | Array, Binary Search, Heap (Priority Queue), Matrix, Sorting | Solution Using Linear Search, Binary Search, Sorting & Binary Search | |
1834 | Single-Threaded CPU | Java | Array, Heap (Priority Queue), Sorting | ||
1962 | Remove Stones to Minimize the Total | Java | Array, Heap (Priority Queue) |
Interactive
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
374 | Guess Number Higher or Lower | Java | Binary Search, Interactive |
Linked List
Math
Matrix
Memoization
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
70 | Climbing Stairs | Java with Dynamic Programming - Tabulation or Memoization | Dynamic Programming, Math, Memoization | ||
509 | Fibonacci Number | Java with Dynamic Programming - Tabulation or Memoization | Dynamic Programming, Math, Memoization, Recursion | ||
1137 | N-th Tribonacci Number | Java | Dynamic Programming, Math, Memoization | Solution Using Dynamic Programming (Iterative) |
Monotonic Stack
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
496 | Next Greater Element I | Java | Array, Hash Table, Monotonic Stack, Stack | ||
503 | Next Greater Element II | Java | Array, Monotonic Stack, Stack | ||
1019 | Next Greater Node In Linked List | Java | Array, Linked List, Monotonic Stack, Stack | ||
2454 | Next Greater Element IV | Java | Array, Monotonic Stack, Stack |
Number Theory
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
1979 | Find Greatest Common Divisor of Array | Java | Array, Math, Number Theory | ||
2413 | Smallest Even Multiple | Java | Math, Number Theory |
Ordered Set
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
220 | Contains Duplicate III | Java with Sliding Window & Ordered Set | Array, Bucket Sort, Ordered Set, Sliding Window, Sorting | Solution Using Sliding Window & Bucket Sort or Sorting |
Prefix Sum
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
238 | Product of Array Except Self | Java | Array, Prefix Sum | ||
523 | Continuous Subarray Sum | Java | Array, Hash Table, Math, Prefix Sum | ||
560 | Subarray Sum Equals K | Java | Array, Hash Table, Prefix Sum | ||
974 | Subarray Sums Divisible by K | Java with Counting or Hash Table | Array, Hash Table, Prefix Sum | ||
1480 | Running Sum of 1D Array | Java | Array, Prefix Sum | ||
1732 | Find the Highest Altitude | Java | Array, Prefix Sum | ||
2389 | Longest Subsequence With Limited Sum | Java | Array, Binary Search, Greedy, Prefix Sum, Sorting | ||
2438 | Range Product Queries of Powers | Java | Array, Bit Manipulation, Prefix Sum |
Queue
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
225 | Implement Stack using Queues | Java | Design, Queue, Stack | ||
232 | Implement Queue using Stacks | Java | Design, Queue, Stack |
Recursion
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
24 | Swap Nodes in Pairs | Java | Linked List, Recursion | Solution Using Iteration | |
206 | Reverse Linked List | Java | Linked List, Recursion | Solution Using Array List or Reverse Nodes Iteratively | |
509 | Fibonacci Number | Java with Dynamic Programming - Tabulation or Memoization | Dynamic Programming, Math, Memoization, Recursion |
Simulation
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
412 | Fizz Buzz | Java | Math, Simulation, String | ||
985 | Sum of Even Numbers After Queries | Java | Array, Simulation | ||
1103 | Distribute Candies to People | Java | Math, Simulation | ||
1603 | Design Parking System | Java | Counting, Design, Simulation | ||
1680 | Concatenation of Consecutive Binary Numbers | Java with Bit Manipulation or Math | Bit Manipulation, Math, Simulation | ||
1920 | Build Array from Permutation | Java | Array, Simulation | ||
2028 | Find Missing Observations | Java | Array, Math, Simulation | ||
2169 | Count Operations to Obtain Zero | Java | Math, Simulation | ||
2352 | Equal Row and Column Pairs | Java | Array, Hash Table, Matrix, Simulation |
Sliding Window
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
3 | Longest Substring Without Repeating Characters | Java with or without Hash Table | Hash Table, Sliding Window, String | ||
219 | Contains Duplicate II | Java | Array, Hash Table, Sliding Window | Solution Using Hash Table | |
220 | Contains Duplicate III | Java with Sliding Window & Bucket Sort or Sliding Window & Ordered Set | Array, Bucket Sort, Ordered Set, Sliding Window, Sorting | Solution Using Sorting | |
438 | Find All Anagrams in a String | Java | Hash Table, Sliding Window, String | ||
567 | Permutation in String | Java | Hash Table, Sliding Window, String, Two Pointers | ||
713 | Subarray Product Less Than K | Java | Array, Sliding Window | ||
904 | Fruit Into Baskets | Java | Array, Hash Table, Sliding Window |
Sorting
Stack
String
Tree
Two Pointers
Union Find
# | Problem | Solution | Difficulty | Topics | Note |
---|---|---|---|---|---|
130 | Surrounded Regions | Java | Array, Breadth-First Search, Depth-First Search, Matrix, Union Find | Solution Using Breadth-First Search or Depth-First Search | |
200 | Number of Islands | Java | Array, Breadth-First Search, Depth-First Search, Matrix, Union Find | Solution Using Breadth-First Search or Depth-First Search | |
1061 | Lexicographically Smallest Equivalent String | Java | String, Union Find | ||
1971 | Find if Path Exists in Graph | Java | Breadth-First Search, Depth-First Search, Graph, Union Find | Solution Using Breadth-First Search, Depth-First Search (Iterative) or Depth-First Search (Recursive) |