63 of #100DaysOfCode Solved Subsets II (handling duplicates) today using recursion & backtracking! 💡 Problem Insight: Generating all subsets is easy… until duplicates enter the game. The challenge is to ensure no duplicate subsets in the final answer. 🔍 Approaches Used: 1️⃣ Optimized Recursion + Backtracking (Used ✅) Sort the array first Use include/exclude pattern Skip duplicates in the exclude step using a loop Time: O(2^n) Space: O(n) (recursion stack) #100DaysOfCode #LeetCode #DSA #Recursion #Backtracking #CodingJourney #CPlusPlus #ProblemSolving
Solved Subsets II with Recursion and Backtracking
More Relevant Posts
-
62 of #100DaysOfCode 🚀 Solved LeetCode 78 – Subsets using a pure recursive (include/exclude) approach in C++. 🔍 Approach: At each index, I make a decision: ✔️ Include the current element in the subset ❌ Exclude the current element This creates a recursion tree exploring all possibilities, and when we reach the end of the array, we store the current subset. 🧠 Core Idea: Pick → Recurse Backtrack → Skip → Recurse Store result when index reaches n #leetcode #cpp #recursion #backtracking #dsa #100DaysOfCode #codingjourney
To view or add a comment, sign in
-
-
Solved “Letter Combinations of a Phone Number” on LeetCode 💡 What looks simple on the surface is actually a clean exercise in recursion + backtracking. 🔍 Key takeaways: - Mapping digits to characters is straightforward, but generating all combinations efficiently is where the thinking comes in - Backtracking helps explore all possibilities while keeping the solution clean and scalable - Important to control recursion depth and maintain state (temp) correctly 💭 What I focused on: - Building combinations incrementally - Reverting state after each recursive call (classic backtracking pattern) - Keeping the solution readable and modular This problem reinforced how powerful recursion is when combined with proper state management. On to the next one 🚀 #DSA #LeetCode #Backtracking #Recursion #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 75/150 🚀 LeetCode 101: Symmetric Tree 🧠 Problem Given the root of a binary tree, check whether it is a mirror of itself. 📌 Example Input → root = [1,2,2,3,4,4,3] Output → true 💡 Approach • Use recursion • Compare left subtree with right subtree • Check mirror structure • Continue recursively ⏱ Time Complexity O(n) 📦 Space Complexity O(h) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) #Day75 #LeetCode #DSA #BinaryTree #Recursion #CodingJourney #ProblemSolving #SoftwareEngineering
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 74/150 🚀 LeetCode 226: Invert Binary Tree 🧠 Problem Given the root of a binary tree, invert the tree and return its root. 📌 Example Input → root = [4,2,7,1,3,6,9] Output → [4,7,2,9,6,3,1] 💡 Approach • Use recursion • Swap left and right child • Recursively invert left subtree • Recursively invert right subtree ⏱ Time Complexity O(n) 📦 Space Complexity O(h) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) #Day74 #LeetCode #DSA #BinaryTree #Recursion #CodingJourney #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
📱 LeetCode 17 – Letter Combinations of a Phone Number | Mastering Backtracking Solved a classic recursion problem today that perfectly demonstrates the power of backtracking and combination building. The challenge: given a string of digits (2–9), generate all possible letter combinations based on the traditional phone keypad mapping. 💡 Key Insight: Each digit maps to multiple characters, and the goal is to explore all possible combinations by picking one character from each digit. This naturally leads to a backtracking approach, where: We build combinations step by step Explore all possibilities recursively Backtrack to try different paths ⚙️ Approach: Use a mapping of digits → letters Traverse the input using recursion Append characters and move forward Store the result when a valid combination is formed 🚀 Complexity: Time: O(4ⁿ) Space: O(n) (recursion stack) 📌 What I learned: How to think in terms of recursion trees Efficiently generating combinations Writing clean and structured backtracking code Problems like this build a strong foundation for tackling advanced topics like DFS, recursion, and combinatorial algorithms. #LeetCode #DSA #Backtracking #Recursion #ProblemSolving #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 35/75 🚀 Solved Count Good Nodes in Binary Tree (LeetCode 1448) today! ✅ All 63/63 test cases passed ⚡ Runtime: 91 ms (Beats ~82%) 💾 Memory: 88.34 MB (Beats ~64%) 🔍 Approach: Used DFS (recursion) while tracking the maximum value seen so far on the path. ✔️ Start from root with initial max = root value ✔️ If current node value ≥ max so far → it's a “good node” ✔️ Update max and continue traversal ✔️ Recursively check left and right subtree 💡 Key Learning: Passing state (like max value) in recursion helps solve path-based problems efficiently. No need to store full paths—just keep track of what's important. Consistency + depth thinking = stronger tree skills 🌳🔥 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
To view or add a comment, sign in
-
-
Day 1 of DSA🚀 Solved "Maximum Depth of Binary Tree" on LeetCode 🌳 Approach I used: Step 1: If the node is null, return 0 (base case) Step 2: Recursively find depth of left subtree Step 3: Recursively find depth of right subtree Step 4: Take max of left and right depth and add 1 This gives the maximum depth (longest path from root to leaf). Simple recursion, but very useful for understanding tree problems. Consistency is more important than perfection 🔥 #LeetCode #DSA #BinaryTree #Recursion #CodeHelp
To view or add a comment, sign in
-
-
Day 30 of #100DaysOfCode 💻 Today’s focus: Permutation Problem Worked on generating all permutations of an array using recursion + backtracking. This problem really tested my understanding of decision trees and tracking visited elements. What stood out today: Every choice creates a new path — and managing those choices efficiently is the key. It’s interesting how a problem that looks simple at first quickly turns into a deep exercise in logic building and control over recursion. Slowly getting more comfortable with backtracking patterns 🚀 #DSA #Backtracking #Recursion #CodingJourney #LeetCode #Consistency #Day30
To view or add a comment, sign in
-
-
🚀 Day 30/100 — LeetCode Challenge Today's problem: Median of Two Sorted Arrays 🧠 Concept: Binary Search on Partition 💡 Key Idea: Instead of merging arrays, use binary search to partition them such that the left half contains smaller elements and the right half contains larger elements. ⚡ Time Complexity: O(log(min(m, n))) 📂 Solutions Repository https://lnkd.in/gkFh2mPZ One of the most challenging and insightful problems so far. A great exercise in advanced binary search thinking. #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #SoftwareEngineering
To view or add a comment, sign in
Explore related topics
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