🔥 DSA Challenge – Day 133/360 🚀 📌 Topic: Recursion + Memoization 🧩 Problem: Word Break Problem Statement: Check if a given string can be segmented into space-separated words from a given dictionary. 🔍 Example: Input: s = "leetcode", wordDict = ["leet", "code"] Output: true 💡 Approach: Optimized (Recursion + Memoization) 1️⃣ Step 1 – Convert the word list into a HashSet for fast lookup 2️⃣ Step 2 – Try all substrings starting from current index 3️⃣ Step 3 – Use memoization array to avoid recomputation of same index ⏱ Complexity: Time: O(n³) Space: O(n) 📚 Key Learning: Memoization helps avoid repeated work and turns an exponential problem into a polynomial one. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #133DaysOfCode #LeetCode
Word Break Problem Solution with Recursion and Memoization
More Relevant Posts
-
🚀 Day 15 of My DSA Journey Today’s problem: Array Rank Transform 💡 Problem Insight: Given an array, replace each element with its rank when the array is sorted. Rank starts from 1 Equal elements → same rank Ranks must be continuous (no gaps) 🧠 Approach: 🔹 Clone and sort the array 🔹 Use a HashMap to assign ranks to unique elements 🔹 Traverse original array and replace values using the map ⚡ Key Learning: 👉 This is a classic example of Coordinate Compression 👉 Helps reduce large values into a smaller ranked range 💻 Code Logic: Sort copy of array Assign rank only if element not already mapped Replace original values using the map 📊 Result: ✅ 43 / 43 test cases passed ⏱ Runtime: 31 ms 📈 Beat: 58.58% 💾 Memory: 74.74 MB (85.14% better than others) 💭 Takeaway: Simple problems can test clean thinking + handling duplicates properly. Hashing + sorting is a powerful combo 🔥 🔥 Consistency Check: Day 15 Complete Building discipline one problem at a time. #DSA #CodingJourney #LeetCode #Java #ProblemSolving #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
Day 92 of #365DaysOfLeetCode Challenge Today’s problem: **Nth Digit (LeetCode 400)** This problem looks simple at first but quickly turns into a pattern-based math challenge. We need to find the **nth digit** in an infinite sequence: `1, 2, 3, ..., 9, 10, 11, 12, ...` 💡 **Key Insight:** Numbers are grouped by digit length: * 1-digit numbers → 9 digits total * 2-digit numbers → 90 × 2 = 180 digits * 3-digit numbers → 900 × 3 = 2700 digits …and so on. Instead of building the sequence, we **skip entire groups** until we land in the correct range. 📌 **Approach:** 1. Determine the digit-length group where `n` lies 2. Identify the exact number containing the nth digit 3. Extract the required digit from that number ⚡ **Time Complexity:** O(log n) ⚡ **Space Complexity:** O(1) **What I learned today:** When dealing with large sequences, **don’t simulate — analyze patterns and jump directly** to the answer. #LeetCode #DSA #CodingChallenge #Java #ProblemSolving #TechJourney #Consistency
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 2 Today I worked on a DSA problem based on arrays: Check if an array is sorted and rotated 🔍 Approach: Instead of finding the exact rotation point, I focused on identifying a pattern: In a sorted and rotated array, the order should break at most once. So, I checked how many times an element is greater than the next element while traversing the array in a circular manner. ✔️ If the count of such breaks is 0 or 1 → valid ❌ If it’s more than 1 → not a sorted rotated array 🧠 Key Takeaway: This problem taught me how pattern observation can simplify logic and avoid unnecessary complexity. Sometimes the best solution is not the most obvious one! 📈 Staying consistent and improving step by step 💪 #100DaysOfCode #DSA #DataStructures #Algorithms #Java #CodingJourney #ProblemSolving #LeetCode #Consistency
To view or add a comment, sign in
-
-
#Day75 of my second #100DaysOfCode Today’s problem was more about spotting patterns than writing code. DSA • Solved Single Element in a Sorted Array (LeetCode 540, Medium) – Brute: linear scan checking pairs → O(n) – Optimal: binary search using index pattern → O(log n) • Key idea: elements appear in pairs, and the single element breaks this pattern • Used position-based logic to decide which half to search This one really showed how observing patterns can simplify the approach. #DSA #BinarySearch #LeetCode #Algorithms #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
#CodeEveryday — My DSA Journey | Day 2 🧩 Problem Solved: Combination Sum II (LeetCode) 💭 What I Learned: Used backtracking to generate all unique combinations whose sum equals the target. Sorted the array initially to efficiently handle duplicates and enable pruning. At each step: ✔️ Skipped duplicate elements using i > n && nums[i] == nums[i-1] ✔️ Stopped recursion early when the current element exceeded the target ✔️ Moved to the next index (i+1) to avoid reusing elements Strengthened my understanding of handling duplicates in recursion and optimizing search space. ⏱ Time Complexity: O(2ⁿ)*k (k is avg length of each combination) 🧠 Space Complexity: O(n) ⚡ Key Takeaways: ✔️ Sorting helps in both pruning and duplicate handling ✔️ Skipping duplicates is crucial for unique combinations ✔️ Backtracking becomes efficient with early stopping conditions 💻 Language Used: Java ☕ 📘 Concepts: Backtracking · Recursion · Arrays · Duplicate Handling · Pruning #CodeEveryday #DSA #LeetCode #Java #Backtracking #ProblemSolving #Algorithms #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 7/50 🔍 Problem: Valid Anagram Today’s problem was about checking whether two strings are anagrams of each other efficiently. 💡 Approach: I used the Character Frequency Count method: First checked if both strings have equal length Used an array of size 26 to track character frequencies Incremented counts for one string and decremented for the other If all values are zero, both strings are anagrams ⚡ This approach avoids sorting and ensures optimal performance. 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(1) 📚 Key Learning: Using frequency arrays is a powerful technique for string problems. It helps achieve constant space complexity and improves efficiency compared to sorting-based approaches. Step by step, getting better at problem solving 💪 #LeetCode #Algorithms #DataStructures #ProblemSolving #CodingJourney #Java #100DaysOfCode #StudentDeveloper #Learning
To view or add a comment, sign in
-
-
#CodeEveryday — My DSA Journey | Day 3 🧩 Problem Solved: Combination Sum III (LeetCode #216) 💭 What I Learned: Used backtracking to find all possible combinations of k numbers (1–9) that sum up to a target n. At each step: ✔️ Decided whether to include the current number ✔️ Reduced both the remaining sum (n) and count (k) ✔️ Ensured each number is used only once by moving to the previous index Applied constraints effectively to prune recursion when: Remaining sum becomes negative Required count becomes invalid This improved my understanding of handling multiple constraints (sum + size) simultaneously in recursion. ⏱ Time Complexity: O(C(9,k) 🧠 Space Complexity: O(k) (recursion depth) ⚡ Key Takeaways: ✔️ Backtracking with multiple constraints requires careful pruning ✔️ Fixed input size can significantly reduce complexity ✔️ Choosing + skipping pattern helps explore all valid combinations 💻 Language Used: Java ☕ 📘 Concepts: Backtracking · Recursion · Combinations · Constraint Handling #CodeEveryday #DSA #LeetCode #Java #Backtracking #ProblemSolving #Algorithms #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
🚀 Day 84 – DSA Journey | Maximum Depth of Binary Tree Continuing my daily DSA practice, today I focused on understanding tree depth and recursive problem solving. 📌 Problem Practiced: Maximum Depth of Binary Tree (LeetCode 104) 🔍 Problem Idea: Find the maximum depth (or height) of a binary tree — the number of nodes along the longest path from the root to a leaf node. 💡 Key Insight: The depth of a tree depends on its subtrees. At every node, we can recursively calculate the depth of left and right subtrees and take the maximum. 📌 Approach Used: • If the node is null → depth is 0 • Recursively calculate depth of left subtree • Recursively calculate depth of right subtree • Return 1 + max(left, right) 📌 Concepts Strengthened: • Binary tree traversal • Recursion • Divide and conquer approach • Tree height calculation ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(h) (recursion stack) 🔥 Today’s takeaway: Breaking problems into smaller subproblems using recursion makes complex tree problems much easier to handle. On to Day 85! 🚀 #Day84 #DSAJourney #LeetCode #BinaryTree #Recursion #Java #ProblemSolving #Coding #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 60 of #100DaysOfCode Another recursion problem that initially feels tricky, but becomes much clearer once the pattern is understood. 🌱 Topic: Recursion / Divide & Conquer ✅ Problem Solved: LeetCode 779 – K-th Symbol in Grammar 🛠 Approach: Base Case: n == 1 → return 0 Observed that each row is divided into two halves: First half → same as previous row Second half → inverse of previous row Calculated midpoint: 2^(n-2) If k <= mid → go to left half Else → go to right half and invert result #100DaysOfCode #Day60 #DSA #Recursion #DivideAndConquer #LeetCode #Java #Algorithms #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 24/100 — #100DaysOfLeetCode Another step forward in strengthening string problem-solving skills 💻🔥 ✅ Problem Solved: 🔹 LeetCode 28 — Find the Index of the First Occurrence in a String 💡 Concepts Used: String Matching Two Pointer / Brute Force Comparison 🧠 Key Learning: The task was to locate the first occurrence of a pattern (needle) inside another string (haystack). I practiced comparing characters sequentially and handling mismatches carefully while traversing the string. ⚡ Insight Gained: Even simple-looking problems help build a strong foundation for advanced string searching algorithms like KMP and Rabin–Karp. Understanding basic string matching logic is essential before moving to optimized pattern-search techniques. Consistency continues 🚀 #100DaysOfLeetCode #LeetCode #DSA #Strings #Algorithms #Java #ProblemSolving #CodingJourney #LearningInPublic #Consistency
To view or add a comment, sign in
-
Explore related topics
- Approaches to Array Problem Solving for Coding Interviews
- Tips for Coding Interview Preparation
- LeetCode Array Problem Solving Techniques
- DSA Preparation Tips for First Interview Round
- Leetcode Problem Solving Strategies
- Common Algorithms for Coding Interviews
- Why Use Coding Platforms Like LeetCode for Job Prep
- Strategies for Solving Algorithmic Problems
- Key DSA Patterns for Google and Twitter Interviews
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development