Day 28 of #100DaysOfCode 💻 Today’s focus: Subsets II (LeetCode 90) Building on yesterday’s Subset Sum (Problem 1), today I explored how the same recursion pattern works when duplicates are involved. 📌 What I focused on: At each step → either pick the element or skip it (same as Subset 1) Sorting the array to handle duplicates Skipping repeated elements at the same recursion level 💡 Realization: Subset II is not a completely new problem—it’s an extension of Subset 1 with an extra constraint. Understanding the base pattern made it much easier to adapt and solve this one. Felt good to see how concepts connect step by step. Still getting more comfortable with recursion and backtracking 🚀 #LeetCode #DSA #Recursion #Backtracking #CodingJourney
Subset II LeetCode Solution with Recursion and Backtracking
More Relevant Posts
-
Day 40 Today I solved: Find N Unique Integers Sum up to Zero (LeetCode 1304) 💡 Problem: Given an integer n, return any array of n unique integers such that their sum equals 0. 💡 My Approach: I used a simple construction-based approach: 1️⃣ Add numbers from 1 to n-1 into the array 2️⃣ Keep track of their sum 3️⃣ Add the last element as -sum to balance everything to zero If sum of first n-1 elements is S, 👉 last element = -S ensures total sum = 0 ⚡ Complexity: Time: O(n) Space: O(n) 🔥 Alternative Idea: Use pairs like (x, -x) and include 0 if n is odd. #LeetCode #DSA #ProblemSolving #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
LeetCode Progress 32/50 — Generate Parentheses Today I worked on a problem focused on recursion and backtracking 🧩 💡 The challenge was to generate all possible combinations of well-formed parentheses for a given number of pairs. 🧠 Approach: Used a backtracking approach by recursively adding opening and closing parentheses while maintaining valid combinations at each step. This ensured only well-formed patterns were generated. ⏱ Time Complexity: O(4ⁿ / √n) 💡 What I learned: This problem highlighted how backtracking can be used to systematically explore valid combinations while pruning invalid paths early. 📈 Strengthening understanding of recursion and improving confidence in solving pattern-generation problems. #LeetCode #DSA #Backtracking #ProblemSolving #Cpp #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
Ever look at a LeetCode problem and think, "Oh, this is just simple math," only to see a constraint of $10^{15}$ staring back at you? That was my experience with the "Count Good Numbers" problem today. The core logic was actually pretty straightforward: even indices get even digits (5 options), and odd indices get prime digits (4 options). But trying to calculate 5^even * 4^odd for massive numbers? Immediate Time Limit Exceeded (TLE). I had to scrap the standard approach and write a custom pow() function using Binary Exponentiation. It’s wild how applying modulo 10^9 + 7 at every single multiplication step within the recursive call is the exact difference between a failing solution and a clean O(log n) pass without integer overflow. Definitely a great reminder that knowing the brute-force math is only half the battle—optimizing it is where the real engineering happens. Back to the grind! #LeetCode #DSA #CPP #CompetitiveProgramming #SoftwareEngineering #CodingJourney
To view or add a comment, sign in
-
-
100 LeetCode problems solved ! and honestly, it's taught me more about thinking than coding. When I started, I used to jump straight to the solution. Now I've learned to slow down — understand the problem, think brute force first, then optimize. Patterns I've been focusing on: → Sliding Window → Two Pointers → Stack & Queue → Kadane's Algorithm → Prefix Sum → Merge Intervals → Linked List The biggest shift wasn't in the number of problems solved — it was learning to recognize WHY a particular approach works, not just HOW. Still a long way to go. But consistency is starting to show results. 100 done. More to come. 🎯 #DSA #LeetCode #CodingJourney #SoftwareEngineering #100Problems
To view or add a comment, sign in
-
-
🚀 Day 14/100 — LeetCode Challenge Solved Delete Node in a Linked List The twist? 👉 You are not given the head of the list At first, I thought deletion wouldn’t be possible without the previous node. But the trick is: 1) Copy the value of the next node 2) Point current node to next->next 3) Effectively “delete” the next node instead 💡 Key Insight: Instead of deleting the given node directly, we shift values and bypass the next node. 🧠 Time Complexity: O(1) 💾 Space Complexity: O(1) 💡 What I learned: Sometimes problems are not about applying a pattern, but about thinking differently with given constraints. Switching from patterns to concepts now. #LeetCode #DSA #100DaysOfCode #Cpp #LinkedList #CodingJourney
To view or add a comment, sign in
-
-
Day 4/100 of my LeetCode Journey Back on track after a short break, and today’s problem was “Kth Smallest Element in a Sorted Matrix.” At first, I didn’t approach it correctly. I was thinking in terms of simple indexing, but this problem required a different perspective. I learned how a min heap can be used to efficiently track the smallest elements across multiple rows. Instead of checking the entire matrix, the idea is to always pick the smallest available element and move forward from there. What I noticed today is that my logic is improving, but I still need to be careful with implementation. Small syntax and indexing mistakes can break the whole solution even when the approach is right. Takeaway: Understanding the approach is important, but writing clean and correct code is equally important. Making steady progress, one problem at a time. Question: Do you also find implementation harder than understanding the logic? #Day4 #LeetCode #DSA #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
One step closer🔥 LeetCode Progress 49/50 — Decode Ways I worked on a fundamental problem focused on dynamic programming and string decoding 🧩 💡 The challenge was to find the number of ways to decode a given digit string into letters (A–Z mapping). 🧠 Approach: Used dynamic programming to track valid decoding ways at each index. Handled edge cases like leading zeros and invalid two-digit combinations carefully. ⏱ Time Complexity: O(n) 💡 What I learned: This problem improved my understanding of DP state building and how to break a problem into smaller subproblems with valid transitions. 📈 Strengthening dynamic programming fundamentals and logical thinking for complex string problems. #LeetCode #DSA #DynamicProgramming #Strings #ProblemSolving #Cpp #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
🚀 Day 27/50 – LeetCode Challenge 🧩 Problem: Count and Say Today’s problem focused on generating a sequence based on reading and describing the previous term, which is a great exercise in string manipulation and pattern building. 📌 Problem Summary: The “Count and Say” sequence is defined as: Start with "1" Each next term is formed by reading the previous term aloud Example: 1 → "one 1" → 11 11 → "two 1s" → 21 21 → "one 2, one 1" → 1211 1211 → "one 1, one 2, two 1s" → 111221 🔍 Approach Used ✔ Started from the base case "1" ✔ Iterated to build each next term ✔ Counted consecutive digits ✔ Formed the new string using: count + digit ✔ Repeated until reaching the required n ⏱ Time Complexity: O(n × m) 📦 Space Complexity: O(m) 💡 Key Learning ✔ Understanding pattern generation problems ✔ Working with string grouping and counting ✔ Building results step by step ✔ Improving attention to detail in iteration This problem shows how simple rules can create complex patterns. Consistency is the key to mastery 🚀 🔗 Problem Link: https://lnkd.in/g_cMVP5a #50DaysOfLeetCode #LeetCode #DSA #Strings #ProblemSolving #CodingJourney #FutureAIEngineer #Consistency
To view or add a comment, sign in
-
-
🧠 Day 32/75: Solving for the "End" from the "Beginning" Linked Lists can be tricky because you can't access elements by index. So, how do you remove the Nth element from the back without knowing the total length? Today’s LeetCode session was a deep dive into Pointer Logic. By maintaining a specific distance between two pointers, I was able to identify and delete the target node in a single traversal. Current Progress: 📅 32 Days Consecutive 🎯 Focus: Advanced Linked List Patterns ⚡ Result: 100% Beats Runtime Another day, another problem solved. The second month is off to a strong start! 💻🔥 #Consistency #100DaysOfCode #DSA #CodingJourney #JavaDeveloper #TechGrowth #LeetCodeChallenge #LinkedInLearning
To view or add a comment, sign in
-
-
I was solving Binary Search Tree to Greater Sum Tree (LeetCode 1038), and my first instinct was pretty straightforward: → Do an inorder traversal to get a sorted array → For each node, find its value in the array → Add all the elements that come after it (greater values) → Replace the node’s value with that sum It felt logical. Clean. Almost satisfying. But then I paused. I realized I was solving the problem in two passes + extra space + nested work, when the tree itself already holds the structure I need. And here’s the honest part — I didn’t come up with the optimized approach on my own. But understanding it was the real win. 👉 Traversing the tree in reverse inorder (Right → Root → Left) 👉 Maintaining a running sum 👉 Updating nodes in a single pass Such a simple shift in perspective, yet so powerful. You don’t always have to discover the best approach yourself. But if you truly understand it once you see it, that’s where growth happens. #DSA #LeetCode #LearningInPublic #BinarySearchTree #KeepLearning
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