Day 3 | LeetCode Learning Journal 🚀 Today I solved Combination Sum (Problem 39) on LeetCode another powerful backtracking problem. Compared to N-Queens, this one focused more on exploring combinations systematically while avoiding unnecessary paths. The interesting part was that we can reuse the same element multiple times, which changes how we design the recursive calls. The key learning was understanding how to: Keep track of the remaining target Use a start index to avoid duplicate combinations. Backtrack properly by removing the last added element after recursion .Instead of generating all possibilities blindly, I learned how pruning works if the current sum exceeds the target, we immediately stop exploring that path. This makes the solution much more efficient. 💡 🌱 What I learned: • How to generate combinations using recursion • Importance of pruning in backtracking • Managing state with push and pop operations • Thinking in terms of decision trees #LeetCode #100DaysOfCode #CodingJourney #Backtracking #DSA #Day3
Combination Sum LeetCode Solution
More Relevant Posts
-
Day 4 | LeetCode Learning Journal 🚀 Today I solved Permutations (Problem 46) on LeetCode another classic backtracking problem that really strengthens recursion fundamentals. Unlike Combination Sum where we focused on reaching a target, this problem was about generating all possible arrangements of given numbers. The main challenge was making sure that each element is used exactly once in every permutation. The key learning was understanding how to: Keep track of which elements are already used. Build permutations step by step. Backtrack properly by removing the last element and marking it unused after recursion. Instead of randomly arranging numbers, I learned how the decision tree works at every level we choose one unused number, explore deeper, and then backtrack to try other possibilities. This systematic exploration ensures we generate all permutations efficiently. 💡 🌱 What I learned: • How to generate permutations using recursion • Using a visited array / boolean tracking • Proper backtracking with push and pop • Visualizing recursion as a decision tree #LeetCode #100DaysOfCode #CodingJourney #Backtracking #DSA #Day4
To view or add a comment, sign in
-
-
Day 10 | LeetCode Learning Journal 🚀 Today I practiced Binary Tree Preorder Traversal (Problem 144) on LeetCode. This problem helped me understand how tree traversal works when we visit the root before its subtrees. 🔑 Key Points: • Traversal order: Root → Left → Right • Visit the current node first • Recursively traverse the left subtree • Then recursively traverse the right subtree • Can also be implemented using a stack (iterative approach) 🌱 What I Learned: • Basics of tree traversal techniques • How recursion naturally fits tree structures • Difference between recursive and iterative traversal • Importance of traversal order in trees • Strengthened understanding of tree fundamentals #LeetCode #100DaysOfCode #DSA #BinaryTree #PreorderTraversal #Day10
To view or add a comment, sign in
-
-
Day 5| LeetCode Learning Journal 🚀 Today I solved Combination Sum II (Problem 40) on LeetCode. Unlike Combination Sum (39), here each element can be used only once and we must avoid duplicate combinations. This small change made the recursion logic more careful and structured. 🔑 Key Points: • Sort the array before backtracking • Skip duplicates using if(i > index && candidates[i] == candidates[i-1]) continue; • Use i + 1 to avoid reusing elements • Proper push → recurse → pop (backtracking) • Stop early when element > remaining target. 🌱 What I Learned: • How to handle duplicates in backtracking problems • Difference between reuse allowed vs not allowed • Importance of pruning to reduce unnecessary recursion • How small constraints completely change the recursion tree • Improved understanding of decision tree visualization #LeetCode #100DaysOfCode #Backtracking #DSA #Day4
To view or add a comment, sign in
-
-
Day 6 | LeetCode Learning Journal 🚀 Today I solved Palindrome Partitioning (Problem 131) on LeetCode. This problem was another strong backtracking challenge, but instead of focusing on sums or combinations, it focused on dividing a string into all possible palindromic partitions. The main challenge was checking palindromes efficiently while exploring every possible cut in the string. 🔑 Key Points: • Use backtracking to try every possible substring • Check if substring is palindrome before choosing it • If valid → push → recurse → pop • Base case when start index reaches string length • Carefully manage substring ranges (start to end) 🌱 What I Learned: • How to generate all possible partitions of a string • Combining recursion with condition checking (palindrome validation) • Difference between combination-style problems and partition-style problems • How recursion explores a decision tree of “cut” vs “don’t cut” • Strengthened understanding of backtracking patterns This problem really improved my clarity on how recursive partitioning works compared to problems like Combination Sum. The structure is similar, but the condition check (palindrome) changes the whole recursion flow. #LeetCode #100DaysOfCode #Backtracking #DSA #Day5 🚀
To view or add a comment, sign in
-
-
🚀 LeetCode — Day 4 Solved: Combination Sum II Today was all about Backtracking + Smart Pruning. Approach: • Sort the array first • Use recursion to explore combinations • Skip duplicates carefully • Prune early if the current sum exceeds target The key learning wasn’t just recursion — it was understanding how to avoid duplicate combinations efficiently and when to stop exploring a path. Backtracking problems really test clarity of thought. One small mistake in conditions → completely wrong output. Step by step, improving recursion confidence and decision-making. Day 4 of consistency. Still building. 🔁🔥 #LeetCode #Day4 #DSA #Backtracking #ProblemSolving #CodingJourney #Consistency #Cpp
To view or add a comment, sign in
-
-
💡 LeetCode Practice – Increasing Triplet Subsequence Today I learned that not every problem can be solved using sorting. Maintaining the original order and thinking in terms of traversal is crucial. 📌 Key Learning: Importance of index order (i < j < k) Optimizing from brute force to O(n) Smart tracking instead of extra space Consistency is building confidence 🚀 #leetcode #codingjourney #webdevelopment #dsa
To view or add a comment, sign in
-
-
Day 18/50 — LeetCode First Bad Version taught me a key lesson: Linear search isn’t always enough Optimization matters for large inputs Binary Search reduces complexity from O(n) → O(log n) Learning to code smarter, not just harder. #Day18 #LeetCode #BinarySearch #DSA #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 16/100 — LeetCode Challenge (Revision Day) Today I focused on revising core problems from Arrays and Two Pointer techniques. Revisited: • Two Sum • Two Sum II • Container With Most Water 🧠 Key Learning: Revision helps reinforce patterns and improves problem-solving speed and confidence. Sometimes going back is the best way to move forward. 📂 Solutions Repository https://lnkd.in/gkFh2mPZ #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #Revision
To view or add a comment, sign in
-
🚀 Day 4/100 — LeetCode Challenge Today I practiced problems based on the Two Pointer technique, a powerful approach for solving array and string problems efficiently. Problems solved: • Valid Palindrome • Two Sum II (Input Array Is Sorted) 🧠 Concept: Two pointers starting from different ends of the array/string and moving toward each other. 💡 Key Learning: Two pointer techniques often help eliminate nested loops and reduce time complexity to O(n). 📂 Solutions Repository https://lnkd.in/gkFh2mPZ Understanding these patterns is helping me recognize more efficient ways to approach problems. #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Day 62 of #100DaysOfCode 💻 Solved: Third Maximum Number (LeetCode 414) 🔍 Problem Statement: Given an integer array, return the third distinct maximum number. If it doesn’t exist, return the maximum number instead. 💡 Approach: The key here is “distinct” values — duplicates don’t count. First, focus on identifying unique numbers Then track the top 3 maximum distinct values If less than 3 distinct values exist → simply return the largest Instead of sorting (which adds extra cost), we can efficiently keep track of the top 3 values while traversing the array once. ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(1) (if done optimally) 📌 Key Learning: This problem teaches how to optimize by avoiding sorting and how to maintain multiple maximums efficiently in a single pass. #Day62 #LeetCode #DSA #CodingJourney #PlacementPrep
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