A structured collection of LeetCode solutions written in Java. Every solution includes a clear explanation of the approach and complexity analysis — because understanding the why matters more than just passing the test.
- Clean, well-commented Java code
- Approach explained in plain English for every problem
- Time and Space complexity on every solution
- Organized by topic — not just dumped in one folder
| Topic | Key Patterns |
|---|---|
| Arrays | Two pointers, sliding window, prefix sum |
| Strings | HashMap, sliding window, palindrome |
| Trees | DFS, BFS, recursion, level order |
| Graphs | DFS, BFS, topological sort, union find |
| Dynamic Programming | Memoization, tabulation, state design |
| Sorting | Merge sort, quick select, counting sort |
| Linked Lists | Fast/slow pointers, reversal, merge |
| Stack & Queue | Monotonic stack, deque, min stack |
| Binary Search | Search space reduction, rotated arrays |
| Math | Number theory, bit manipulation, GCD |
Every file follows this structure:
// Problem: Two Sum (Easy) — LeetCode #1
// Link: https://leetcode.com/problems/two-sum/
// Approach: Store each number's complement in a HashMap.
// On each iteration, check if the complement already exists.
// Time Complexity: O(n)
// Space Complexity: O(n)
class Solution {
public int[] twoSum(int[] nums, int target) {
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement))
return new int[]{map.get(complement), i};
map.put(nums[i], i);
}
return new int[]{};
}
}1. READ -> Understand fully before touching the keyboard
2. BRUTE -> Naive solution first — get it working
3. PATTERN -> Sliding window? DP? Graph traversal? Find it.
4. OPTIMIZE -> Reduce time and space, justify every step
5. CODE -> Clean implementation with meaningful names
6. PUSH -> Daily commit. Consistency over everything.
If this repo helped you in any way, a star would mean a lot ⭐