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
Combination Sum II LeetCode Solution
More Relevant Posts
-
🚀 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
-
-
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 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
-
-
🚀 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 8 / 100 Days of Code Challenge 💻🔥 Solved LeetCode 160 — Intersection of Two Linked Lists 🔗 🔍 Problem • Given two singly linked lists, find the node where they intersect • If no intersection exists, return null ⚙️ Approach (Two Pointer Switching) • Use two pointers starting at headA and headB • Traverse both lists simultaneously • When a pointer reaches the end, redirect it to the other list’s head 🔄 • Continue until both pointers meet • The meeting point is the intersection node (or null if no intersection) 💡 Key Learning • Equalizing path lengths without explicitly calculating them • Efficient pointer manipulation technique • Clean and optimal solution without extra space ⏱ Complexity • Time: O(n + m) ⏳ • Space: O(1) 📦 Consistency continues 🚀 #100DaysOfCode #LeetCode #DSA #LinkedList #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 18/50 – LeetCode Challenge 🧩 Problem #108 – Convert Sorted Array to Binary Search Tree Today’s problem focused on building a height-balanced Binary Search Tree (BST) from a sorted array — a great mix of recursion and tree concepts. 📌 Problem Summary: Given a sorted array, convert it into a height-balanced BST. A BST is height-balanced if the depth of the two subtrees of every node never differs by more than one. 🔍 Approach Used ✔ Used a divide and conquer strategy ✔ Selected the middle element of the array as the root ✔ Recursively built the left subtree from the left half ✔ Recursively built the right subtree from the right half This ensures the tree remains balanced. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(log n) (recursion stack) 💡 Key Learning ✔ Understanding tree construction from arrays ✔ Applying recursion effectively ✔ Importance of choosing the middle element for balance ✔ Strengthening concepts of BST and divide & conquer This problem helped reinforce how recursive thinking can simplify complex tree-building problems. Consistency is the key to mastery 🚀 🔗 Problem Link: https://lnkd.in/gymByPPA #50DaysOfLeetCode #LeetCode #DSA #BinarySearchTree #Recursion #ProblemSolving #CodingJourney #FutureAIEngineer #Consistency
To view or add a comment, sign in
-
-
🚀 Day 9/50 – LeetCode Challenge 🧩 Climbing Stairs Today’s problem looked simple at first — but it beautifully demonstrates the power of Dynamic Programming. 📌 Problem Summary: You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 step or 2 steps. How many distinct ways can you reach the top? 🧠 Key Insight To reach step n, you can only come from: Step n-1 (taking 1 step) Step n-2 (taking 2 steps) So the formula becomes: ways(n) = ways(n-1) + ways(n-2) This is exactly like the Fibonacci sequence. 🔍 Approach Used (Optimized DP) Instead of using recursion (which is slow), I: ✔️ Used two variables to store previous results ✔️ Iteratively calculated the next value ✔️ Avoided extra array space ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) 💡 Key Learning: ✔️ Recognizing Fibonacci pattern in problems ✔️ Converting recursion into iterative DP ✔️ Optimizing space usage ✔️ Building strong DP fundamentals Simple problem. Powerful concept. Every small step improves problem-solving ability 🚀 🔗 Problem Link: https://lnkd.in/g7mHjHHz #50DaysOfLeetCode #LeetCode #DynamicProgramming #DSA #ProblemSolving #CodingJourney #FutureAIEngineer #Consistency
To view or add a comment, sign in
-
-
🚀 Day 18/100 — LeetCode Challenge (Revision Day) Today I revised Stack-based problems: • Valid Parentheses • Min Stack 🧠 Key Learning: Stack is extremely useful for handling nested structures and designing efficient data structures with constant-time operations. Revisiting these problems helped reinforce core concepts and design thinking. 📂 Solutions Repository https://lnkd.in/gkFh2mPZ #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #Revision
To view or add a comment, sign in
-
🚀 Day 136 – LeetCode 150 Days Challenge Today’s problem was about generating Combinations using Backtracking. 🧩 Problem Given two integers n and k, return all possible combinations of k numbers chosen from the range [1, n]. Example: Input: n = 4, k = 2 Output: [1,2] [1,3] [1,4] [2,3] [2,4] [3,4] 💡 Key Idea This is a classic Backtracking problem. Instead of generating all subsets and filtering them, we build combinations step by step. Steps: 1️⃣ Start from a number 2️⃣ Add it to the current combination 3️⃣ Recursively choose the next numbers 4️⃣ When the combination size becomes k, store it 5️⃣ Backtrack and try other possibilities Backtracking helps us explore all valid possibilities efficiently. ⚙️ Approach Maintain a temporary vector t to store the current combination. Start iterating from start to n. Add the number to the current combination. Recursively call the function for the next numbers. Remove the number (backtrack) to explore other choices. ⏱ Complexity Time Complexity: O(C(n, k) × k) Space Complexity: O(k) (recursion stack) 📚 What I Learned Today ✔️ How Backtracking explores combinations efficiently ✔️ Importance of adding and removing elements (push/pop) during recursion ✔️ How recursion trees help visualize combination generation 🔥 Consistency is the key to mastering DSA. #LeetCode #DSA #Backtracking #150DaysOfCode #CodingChallenge #Cpp #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 2/100 — LeetCode Challenge Continuing my 100 Days of LeetCode journey to strengthen my Data Structures and problem-solving skills. Today's problems: • Contains Duplicate • Valid Anagram 🧠 Concepts Used HashSet and HashMap for efficient lookups and frequency counting. 💡 Key Learning Hash-based data structures are extremely useful for reducing time complexity from O(n²) to O(n) in many array and string problems. 📂 Solutions Repository https://lnkd.in/gkFh2mPZ Day 2 complete. Excited to continue learning and improving every day. #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #SoftwareEngineering
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