🚀 Day 73 of #100DaysOfCode 💻 Problem 39: Combination Sum ✅ Successfully solved on LeetCode! 🔍 Problem Summary: Given an array of distinct integers candidates and a target integer target, return all unique combinations where the chosen numbers sum to target. You can use the same number unlimited times. 🧠 Approach (Backtracking): • Explore all possible combinations recursively • Stop when sum exceeds target (pruning) • Store valid combinations when target becomes 0 • Reuse same element to allow unlimited picks ⚡ Key Insight: Backtracking helps efficiently generate combinations while avoiding unnecessary computations using pruning. 💡 What I Learned: • Strong grip on recursion + backtracking • How to reduce search space using pruning • Writing clean and optimized recursive solutions 🔥 73 days strong — consistency is paying off! #Day73 #100DaysOfCode #LeetCode #DSA #Backtracking #CodingJourney
100DaysOfCode: Combination Sum Solution on LeetCode
More Relevant Posts
-
🚀 Day 79 of #100DaysOfCode Today, I solved LeetCode 32 – Longest Valid Parentheses, a challenging problem that focuses on stack-based logic and string processing. 💡 Problem Overview: Given a string containing only '(' and ')', the goal is to find the length of the longest valid (well-formed) parentheses substring. 🧠 Approach: ✔️ Used a stack-based approach to track indices ✔️ Initialized stack with -1 to handle edge cases ✔️ For every closing bracket, popped from stack ✔️ Calculated valid substring length using current index and stack top This approach efficiently tracks valid sequences and avoids reprocessing. ⚡ Key Takeaways: Stack is powerful for handling matching problems Index-based tracking simplifies substring calculations Handling edge cases (like invalid starting brackets) is crucial 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(n) Solving hard problems step by step and improving every day 🚀 #LeetCode #100DaysOfCode #DSA #Stack #Strings #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep #HardProblems
To view or add a comment, sign in
-
-
🚀 Day 70 of #100DaysOfCode 📌 LeetCode Q3: 3Sum 💡 Problem: Find all unique triplets in the array which gives the sum of 0. 🧠 Approach I Used: - First, sorted the array - Fixed one element - Applied two-pointer technique for the remaining part - Skipped duplicates to avoid repeated triplets ⚡ Key Insight: Instead of brute force O(n³), using sorting + two pointers reduces it to O(n²) ❗ Edge Cases Handled: - Duplicate values - No valid triplets - Negative + positive mix ⏱ Complexity: - Time: O(n²) - Space: O(1) (excluding result) 🔥 Takeaway: Two-pointer + sorting = deadly combo for array problems 💯 💬 Open to feedback & better approaches! #Day70 #100DaysOfCode #LeetCode #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 92/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 347 – Top K Frequent Elements(Medium) 🧠 Approach: Count the frequency of each element using a hashmap, then sort the elements based on frequency in descending order and pick the top k. 💻 Solution: class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: freq = {} for num in nums: freq[num] = freq.get(num, 0) + 1 sorted_items = sorted(freq.items(), key=lambda x: x[1], reverse=True) return [item[0] for item in sorted_items[:k]] ⏱ Time | Space: O(n log n) | O(n) 📌 Key Takeaway: Hashmaps combined with sorting provide a simple way to solve frequency-based problems, though heaps or bucket sort can optimize performance further. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
🚀 Day 64 of #100DaysOfCode Today, I solved LeetCode 290 – Word Pattern, a problem that focuses on pattern matching and mapping relationships. 💡 Problem Overview: Given a pattern and a string, the task is to determine if the string follows the same pattern, ensuring a one-to-one mapping between characters in the pattern and words in the string. 🧠 Approach: To solve this problem efficiently, I focused on: ✔️ Using a hashmap to map pattern characters to words ✔️ Ensuring a bijection (one-to-one mapping) between pattern and words ✔️ Validating consistency throughout the traversal This approach ensures correctness while maintaining simplicity. ⚡ Key Takeaways: Hashmaps are powerful for mapping relationships Ensuring bijection is crucial in pattern problems Clean validation logic avoids edge-case errors 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(n) Building strong fundamentals one problem at a time 🚀 #LeetCode #100DaysOfCode #DSA #HashMap #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 78 of #100DaysOfCode Today, I solved LeetCode 154 – Find Minimum in Rotated Sorted Array II, a problem that focuses on binary search and handling edge cases with duplicates. 💡 Problem Overview: Given a rotated sorted array that may contain duplicates, the goal is to find the minimum element efficiently. 🧠 Approach: ✔️ Applied modified binary search ✔️ Compared mid element with the right boundary ✔️ Carefully handled duplicate values to avoid incorrect elimination of search space This approach ensures correctness even when duplicates are present. ⚡ Key Takeaways: Binary search can be adapted for complex scenarios Duplicates introduce edge cases that must be handled carefully Choosing the correct condition is key to narrowing the search space 📊 Complexity Analysis: Time Complexity: O(log n) (average), O(n) (worst case due to duplicates) Space Complexity: O(1) Strengthening problem-solving with optimized approaches 🚀 #LeetCode #100DaysOfCode #DSA #BinarySearch #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
To view or add a comment, sign in
-
-
Day 90 of #100DaysOfCode Today I solved "Path Sum III" on LeetCode using a DFS + Recursion approach. Key Idea: We need to count all paths where the sum of node values equals the target. The path doesn’t have to start from the root — it can start from any node! Approach: • For every node, treat it as a starting point • Use DFS to explore all downward paths • Reduce the target at each step (target - node->val) • If a node matches the remaining target → count it • Repeat the process for left and right subtrees Why this works: Every node gets a chance to act as the starting point, and DFS ensures we explore all possible paths efficiently. Concepts Used: • Binary Trees • Depth First Search (DFS) • Recursion • Backtracking (implicit) Time Complexity: O(n²) in worst case Space Complexity: O(h) This problem helped me understand how to explore all possible paths in a tree, not just root-based ones — a big step forward in mastering tree problems From single path problems → to handling multiple dynamic paths… growing every day #Day90 #100DaysOfCode #LeetCode #BinaryTree #DFS #Cpp #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 65/100 – LeetCode Challenge. 🔍 Problem: Remove All Adjacent Duplicates in String. At first glance, this problem looks like a simple string manipulation task… but the real magic lies in using the right approach! 💡 Approach Used: Stack (via string) 👉 Idea: Traverse the string If current character = last character of result → remove it Else → add it 🧠 Key Insight: We simulate a stack using a string. Last added character = top of stack → result.back() ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(n) 📌 Takeaway: Whenever you see adjacent duplicate removal / pair cancellation, think of stack pattern instantly! 💬 Example: Input: "abbaca" Output: "ca" #Day65 #100DaysOfCode #DSA #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
My first “All Kill” in today’s LeetCode contest! 🚀 I gave the LeetCode Weekly Contest 498 and solve 4/4 questions. It was a relatively easier contest as most of the questions didn't test very high problem-solving or implementation skills, but were topic-based. If you are familiar with the underlying topics, you can solve these questions. I was lucky enough to be familiar with all these topics!! Here’s a brief breakdown of my approach: 1. Smallest Stable Index I (Easy) The constraints were small enough that brute force would work, but I noticed early that the 2nd question was the same as the first one and thus directly implemented an optimized approach in linear time. This way I could use the same code for the Q2. Just simply compute a prefix array for Max and suffix array for Min and get the first index that satisfies the conditions. We don't actually need a prefix array, the max can be calculated in the same loop as the loop to get the stable index, but to write the code faster i didn't think much and just implemented it with a prefix and suffix array. 2. Smallest Stable Index II (Medium) Same logic as Q1, just larger constraints, linear time solution works well. 3. Multi Source Flood Fill (Medium) Standard multi-source BFS. • Push all sources into the queue initially • Maintain a time matrix to track earliest arrival • If multiple colours reach a cell at the same time → choose the maximum colour 4. Count Good Integers on a Grid Path (Hard) A really interesting Digit DP + path simulation problem. Pretty standard. The only tricky part is to think of flattening the 2D grid • Convert each number into a 16-digit grid • Precompute the path positions from the directions • Apply digit DP with state tracking: • current index • last digit (to ensure non-decreasing sequence) • tight constraint • Count all valid numbers in range [l, r] Overall, a great contest and a confidence booster 💯 Now focusing on improving speed and handling tougher problems. #LeetCode #WeeklyContest #CompetitiveProgramming #DSA #ProblemSolving #LeetCodeContest #AllKill
To view or add a comment, sign in
-
-
🔥 Day 173 of My LeetCode Journey Problem 113: Path Sum II 💡 Problem Insight: Today’s problem extends Path Sum — instead of just checking existence, you must return all root-to-leaf paths whose sum equals the target. This shift from a Boolean list makes the problem more complex. 🧠 Concept Highlight: The solution uses DFS + backtracking: Traverse the tree while maintaining the current path Subtract node values from the target sum When a valid leaf is reached, store the path Backtrack to explore other possibilities Backtracking is essential to avoid mixing paths. 💪 Key Takeaway: Whenever a problem asks for all possible paths/combinations, backtracking is the go-to technique. Managing state correctly is more important than traversal itself. ✨ Daily Reflection: This problem reinforced the need for discipline when storing results. Without proper backtracking, solutions become incorrect quickly. #Day173 #LeetCode #BinaryTree #DFS #Backtracking #PathSum #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 17 / 100 Days of Code Challenge 💻🔥 Solved LeetCode 901 — Online Stock Span 📈 🔍 Problem • Design a system that calculates the stock span for each day • Span = number of consecutive days (including today) where price is less than or equal to today’s price ⚙️ Approach (Monotonic Stack) • Use a stack to store pairs of (price, span) • For each new price, remove all smaller or equal prices from the stack • Add their span to current span • Push the current price with updated span 💡 Key Learning • Strong understanding of monotonic stack pattern • Avoiding repeated comparisons using accumulated span • Optimizing from O(n²) to O(n) (amortized) ⏱ Complexity • Time: O(n) ⏳ • Space: O(n) 📦 Consistency continues 🚀 #100DaysOfCode #LeetCode #DSA #Stack #ProblemSolving #Consistency
To view or add a comment, sign in
-
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