-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
334 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# **How to Master LeetCode and Grind Effectively** | ||
|
||
## **1. Build a Strong Foundation** | ||
|
||
Before grinding LeetCode, make sure you understand: | ||
|
||
- **Data Structures**: Arrays, HashMaps, Trees, Graphs, Stacks, Queues, Heaps, Linked Lists, Tries | ||
- **Algorithms**: Sorting, Recursion, Sliding Window, Two Pointers, Binary Search, Dynamic Programming, Backtracking | ||
|
||
## **2. Follow a Structured Roadmap** | ||
|
||
Start with **easy** problems, then move to **medium**, and finally **hard** problems. | ||
|
||
### **Step-by-Step Plan** | ||
|
||
### ✅ **Step 1: Learn Patterns Instead of Memorizing** | ||
|
||
Master **common patterns** like: | ||
|
||
- **Sliding Window** (e.g., Longest Substring Without Repeating Characters) | ||
- **Two Pointers** (e.g., Valid Palindrome) | ||
- **Prefix Sum / HashMap** (e.g., Subarray Sum Equals K) | ||
- **Binary Search** (e.g., Find Minimum in Rotated Sorted Array) | ||
- **Dynamic Programming** (e.g., House Robber, Longest Increasing Subsequence) | ||
|
||
### ✅ **Step 2: Solve Easy-Medium Problems First** | ||
|
||
Follow **Blind 75** or **NeetCode 150** problem lists. | ||
|
||
### ✅ **Step 3: Solve Variations of Problems** | ||
|
||
For each problem type, solve **3-5 similar questions** to reinforce the pattern. | ||
|
||
### ✅ **Step 4: Time Yourself & Optimize Solutions** | ||
|
||
- Aim for **brute force first**, then optimize using a **better approach**. | ||
- If you can't optimize, **study the solution** and try to implement it from scratch. | ||
|
||
### ✅ **Step 5: Track Progress & Revisit Hard Problems** | ||
|
||
- Maintain a **spreadsheet** to track solved problems and approaches used. | ||
- If you struggle with a problem, **redo it after a week**. | ||
|
||
--- | ||
|
||
## **3. Grinding Strategy** | ||
|
||
### **Beginner (0-100 problems)** | ||
|
||
- Solve **easy problems (Arrays, HashMaps, Two Pointers, Sliding Window)** | ||
- Focus on **understanding basic data structures** | ||
- **Target: 1-2 problems per day** | ||
|
||
### **Intermediate (100-300 problems)** | ||
|
||
- Start **Medium problems** with **Recursion, DFS/BFS, Prefix Sum** | ||
- Learn **Dynamic Programming basics** (bottom-up & top-down) | ||
- **Target: 2-3 problems per day** | ||
|
||
### **Advanced (300+ problems)** | ||
|
||
- Focus on **Graph algorithms, Tries, Segment Trees** | ||
- Solve **Hard problems** | ||
- Optimize code and explain solutions in mock interviews | ||
- **Target: 3-5 problems per day** | ||
|
||
--- | ||
|
||
## **4. Use the Right Tools** | ||
|
||
- **NeetCode 150 / Blind 75** → Structured problem list | ||
- **LeetCode Discuss** → Learn optimized solutions | ||
- **Codeforces / AtCoder** → For speed and problem-solving skills | ||
- **Mock Interviews** → Practice under pressure | ||
|
||
--- | ||
|
||
## **5. Mindset & Discipline** | ||
|
||
- **Consistency beats cramming** – Solve problems **daily** | ||
- **Don’t be afraid to fail** – Learn from mistakes and **debug code** | ||
- **Explain solutions out loud** – Helps with interviews | ||
- **Take breaks** – Avoid burnout | ||
|
||
🔥 **Grind smart, not just hard!** 🚀 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Most Commonly Asked LeetCode Techniques | ||
|
||
## 1️⃣ Sliding Window | ||
|
||
- **Use case:** Problems involving contiguous subarrays or substrings. | ||
- **Common problems:** | ||
- [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | ||
- [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/) | ||
- [Find All Anagrams in a String](https://leetcode.com/problems/find-all-anagrams-in-a-string/) | ||
|
||
--- | ||
|
||
## 2️⃣ Two Pointers | ||
|
||
- **Use case:** Searching, sorting, or working with sorted arrays. | ||
- **Common problems:** | ||
- [Two Sum II - Input Array Is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) | ||
- [3Sum](https://leetcode.com/problems/3sum/) | ||
- [Container With Most Water](https://leetcode.com/problems/container-with-most-water/) | ||
|
||
--- | ||
|
||
## 3️⃣ Hashing (HashMap / HashSet) | ||
|
||
- **Use case:** Problems requiring quick lookups, frequency counts, or duplicate detection. | ||
- **Common problems:** | ||
- [Two Sum](https://leetcode.com/problems/two-sum/) | ||
- [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | ||
- [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/) | ||
|
||
--- | ||
|
||
## 4️⃣ Prefix Sum | ||
|
||
- **Use case:** Subarray sum-related problems. | ||
- **Common problems:** | ||
- [Subarray Sum Equals K](https://leetcode.com/problems/subarray-sum-equals-k/) | ||
- [Find Pivot Index](https://leetcode.com/problems/find-pivot-index/) | ||
- [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) | ||
|
||
--- | ||
|
||
## 5️⃣ Binary Search | ||
|
||
- **Use case:** Searching in sorted arrays or search-space optimization. | ||
- **Common problems:** | ||
- [Binary Search](https://leetcode.com/problems/binary-search/) | ||
- [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/) | ||
- [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) | ||
|
||
--- | ||
|
||
## 6️⃣ Dynamic Programming (DP) | ||
|
||
- **Use case:** Problems with overlapping subproblems and optimal substructure. | ||
- **Common problems:** | ||
- [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) | ||
- [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) | ||
- [House Robber](https://leetcode.com/problems/house-robber/) | ||
|
||
--- | ||
|
||
## 7️⃣ Backtracking | ||
|
||
- **Use case:** Generating all possible combinations or permutations. | ||
- **Common problems:** | ||
- [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/) | ||
- [Combination Sum](https://leetcode.com/problems/combination-sum/) | ||
- [Sudoku Solver](https://leetcode.com/problems/sudoku-solver/) | ||
|
||
--- | ||
|
||
## 8️⃣ Bit Manipulation | ||
|
||
- **Use case:** Finding unique elements or performing bitwise operations. | ||
- **Common problems:** | ||
- [Single Number](https://leetcode.com/problems/single-number/) | ||
- [Power of Two](https://leetcode.com/problems/power-of-two/) | ||
- [Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/) | ||
|
||
--- | ||
|
||
## 9️⃣ Stack & Monotonic Stack | ||
|
||
- **Use case:** Problems related to parentheses, stock spans, and histogram bars. | ||
- **Common problems:** | ||
- [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | ||
- [Daily Temperatures](https://leetcode.com/problems/daily-temperatures/) | ||
- [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) | ||
|
||
--- | ||
|
||
## 🔟 Graphs & BFS/DFS | ||
|
||
- **Use case:** Traversing connected components, shortest paths, or cycle detection. | ||
- **Common problems:** | ||
- [Number of Islands](https://leetcode.com/problems/number-of-islands/) | ||
- [Word Ladder](https://leetcode.com/problems/word-ladder/) | ||
- [Course Schedule](https://leetcode.com/problems/course-schedule/) | ||
|
||
--- | ||
|
||
## 1️⃣1️⃣ Heap / Priority Queue | ||
|
||
- **Use case:** Problems that require frequent min/max element retrieval. | ||
- **Common problems:** | ||
- [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/) | ||
- [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/) | ||
- [Merge K Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/) | ||
|
||
--- | ||
|
||
## **Want a list of problems for a specific topic?** 🚀 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function reverse_string(str: string) { | ||
let reversed = ''; | ||
|
||
for (let i = str.length - 1; i >= 0; i--) { | ||
reversed += str[i]; | ||
} | ||
|
||
return reversed; | ||
} | ||
console.log(reverse_string('hello')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package neetcode_150.src; | ||
|
||
public class IsValidPalindrome { | ||
public static void main(String[] args) { | ||
String str = "madam"; | ||
System.out.println(isPalindrome(str)); | ||
} | ||
|
||
public static boolean isPalindrome(String str) { | ||
int left = 0; | ||
int right = str.length() - 1; | ||
|
||
while (left < right) { | ||
|
||
while (left < right && !Character.isLetterOrDigit(str.charAt(left))) { | ||
left++; | ||
} | ||
while (left < right && !Character.isLetterOrDigit(str.charAt(right))) { | ||
right--; | ||
} | ||
|
||
if (Character.toLowerCase(str.charAt(left)) != Character.toLowerCase(str.charAt(right))) { | ||
return false; | ||
} | ||
|
||
left++; | ||
right--; | ||
} | ||
|
||
return true; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
data_structures/neetcode_150/src/LongestConsecutiveSequence.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package neetcode_150.src; | ||
|
||
import java.util.HashSet; | ||
|
||
/** | ||
* Longest Consecutive Sequence | ||
* - Given an unsorted array of integers `nums`, return the length of the | ||
* consecutive elements sequence | ||
* - You must write an algorithm that runs in `O(n)` time | ||
*/ | ||
public class LongestConsecutiveSequence { | ||
public static void main(String[] args) { | ||
int[] nums = { 100, 4, 200, 1, 3, 2 }; | ||
System.out.println("Brute Force : " + bruteForce(nums)); | ||
|
||
System.out.println("Optimal : " + longestConsecutive(nums)); | ||
} | ||
|
||
/** | ||
* Optimal Solution | ||
* | ||
* @param nums | ||
* @return | ||
*/ | ||
private static int longestConsecutive(int[] nums) { | ||
if (nums.length == 0 || nums == null) { | ||
return 0; | ||
} | ||
|
||
HashSet<Integer> numsSet = new HashSet<>(); | ||
|
||
for (int i = 0; i < nums.length; i++) { | ||
numsSet.add(nums[i]); | ||
} | ||
|
||
int longestSub = 0; | ||
|
||
for (int num : numsSet) { | ||
if (numsSet.contains(num - 1)) { | ||
continue; | ||
} else { | ||
int currentNum = num; | ||
int currentSub = 1; | ||
|
||
while (numsSet.contains(currentNum + 1)) { | ||
currentNum++; | ||
currentSub++; | ||
} | ||
|
||
longestSub = Math.max(longestSub, currentSub); | ||
} | ||
} | ||
|
||
return longestSub; | ||
} | ||
|
||
/** | ||
* Just Testing BruteForce | ||
* | ||
* @param nums | ||
* @return | ||
*/ | ||
private static int bruteForce(int[] nums) { | ||
int maxLength = 0; | ||
|
||
for (int num : nums) { | ||
if (!contains(nums, num - 1)) { | ||
int currentNum = num; | ||
int currentStreak = 1; | ||
|
||
while (contains(nums, currentNum + 1)) { | ||
currentNum++; | ||
currentStreak++; | ||
} | ||
|
||
maxLength = Math.max(maxLength, currentStreak); | ||
} | ||
} | ||
|
||
return maxLength; | ||
} | ||
|
||
private static boolean contains(int[] nums, int target) { | ||
for (int num : nums) { | ||
if (num == target) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} |