🔥 Day 22 | Round 4 — Handling Duplicates with Backtracking! 🔥 Solved a LeetCode problem — Permutations II 💡 This problem focuses on generating all unique permutations using backtracking while carefully handling duplicate elements. By using a set at each recursion level and swapping elements in place, the solution avoids repeated permutations efficiently 💪 Great practice for mastering recursion with constraints 🚀 🔹 Concepts Used: Backtracking | Recursion | Hash Set 🔹 Key Takeaway: Pruning duplicate choices early saves a lot of unnecessary computation 🧠 #30DaysOfCode #Round4 #Day22 #LeetCode #Backtracking #Recursion #Permutations #DSA #ProblemSolving #CodingChallenge #DeveloperJourney #CodeEveryday #CPlusPlus #LearnByDoing #ConsistencyIsKey 🚀
Mastering Backtracking with Recursion and Hash Sets
More Relevant Posts
-
🚀 Day 55 of LeetCode Problem Solving Journey — 100 Days LeetCode Challenge Today, I solved LeetCode #682 — Baseball Game using C++, under the guidance of Trainer NEKAL SINGH SALARIA Singh at REGex Software Services. 🔍 Problem Summary: You are given a list of operations representing scores in a game. Each operation can be: A number → add it as a new score "+" → add last two scores "D" → double last score "C" → remove last score The goal is to compute the total score after applying all operations. 🧠 Approach Used: I used a stack to store scores dynamically: Push numbers normally "C" → pop last score "D" → push double of top "+" → sum last two values and push result The stack perfectly models the last-in-first-out behavior required by the rules. 📚 Key Learnings of the Day ✔ Stack is ideal for undo/remove operations ✔ Simulation problems require precise rule implementation ✔ Maintaining previous states simplifies logic ✔ LIFO structures naturally fit many real-world scenarios ⏱ Complexity • Time Complexity: O(n) • Space Complexity: O(n) 💡 This problem reinforces a powerful pattern: If you need to repeatedly access or remove the most recent element → think Stack. #Day55 #100DaysLeetCodeChallenge #LeetCode #RegexSoftwareServices #NekalSingh #ProblemSolving #DSA #CPlusPlus #CodingChallenge #ProgrammingJourney #Stack #KeepGrowing
To view or add a comment, sign in
-
-
Day 48/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 338 – Counting Bits (Easy) 🧠 Approach: For each number from 0 to n, count the number of set bits using the trick x & (x - 1), which removes the lowest set bit in each step. 💻 Solution: class Solution: def countBits(self, n: int) -> List[int]: counts = [0] for i in range(1,n+1): count=0 while i: i&=(i-1) count+=1 counts.append(count) return counts ⏱ Time | Space: O(n log n) | O(n) 📌 Key Takeaway: The bit manipulation trick x & (x - 1) efficiently removes the lowest set bit and helps count 1's in binary representation. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
Day 42/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 287 – Find the Duplicate Number (Medium) 🧠 Approach: Traverse the array while storing visited numbers in a set. If a number is already present in the set, that number is the duplicate. 💻 Solution: class Solution: def findDuplicate(self, nums: List[int]) -> int: seen = set() for num in nums: if num in seen: return num seen.add(num) ⏱ Time | Space: O(n) | O(n) 📌 Key Takeaway: Using a hash set is a simple and effective way to detect duplicates by tracking previously seen elements. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
🔥 Day 15 of My Coding Journey Today I solved the classic Two Sum problem on LeetCode. 💻 At first glance, it looks simple — but the real learning was about optimizing the approach. Instead of using a brute-force method (O(n²)), I implemented a HashMap approach to reduce the time complexity to O(n). ⚡ Key takeaways from today: ✅ Understanding time complexity matters ✅ Using HashMap improves lookup efficiency ✅ Writing clean and optimized logic builds confidence ✅ Small problems strengthen big thinking Every day I’m getting better at breaking down problems and thinking in terms of optimization. Consistency > Motivation 💪
To view or add a comment, sign in
-
🚀 LeetCode Daily Challenge – Binary Gap 📌 Problem: Binary Gap 🔗 LeetCode - Daily Question Today’s problem focused on analyzing binary representation using bit manipulation. The goal: Find the maximum distance between two consecutive set bits (1s) in a number’s binary form. Brute force string conversion? Possible—but unnecessary. ❌ Bitwise traversal? Clean and optimal. ✅ 💡 Key Insight: - Traverse bits from LSB to MSB - Track the position of the last seen "1" - For every new "1", compute distance from previous - Maintain the maximum gap 🛠 Approach: • Iterate while "n > 0" • Check "(n & 1)" for set bit • Track positions using a counter • Update max distance • Right shift "n" ⏱ Complexity: Time: O(log n) Space: O(1) ✔ Accepted ✔ Clean bit manipulation logic ✔ Reinforced fundamentals of binary traversal Takeaway: Sometimes the simplest bit tricks outperform heavier approaches—clarity wins. Practicing DSA daily with LeetCode, learning alongside CoderArmy, and guided by Rohit Negi, Aditya Tandon Day 26 done. Staying consistent. 🚀 #Day26/90 #LeetCode #DSA #BitManipulation #ProblemSolving #CPlusPlus #LearningInPublic #ProblemSolving2026
To view or add a comment, sign in
-
-
Day 52 Solved Prime Number of Set Bits in Binary Representation on LeetCode today! 🔢 Problem Summary: Given two integers left and right, count how many numbers in that range have a prime number of set bits (1s) in their binary representation. 💡 Approach: For each number in the range: Count the number of set bits using bit manipulation (n & 1, n >> 1) Check whether the count is a prime number Increment the answer if the set bit count is prime ⚡ Key Learning: Bit manipulation may look simple, but it builds strong logical thinking and optimization skills. 52 days of consistency and still going strong 💪 #LeetCode #Day52 #DSA #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Stop using `.pop()` or `delete` inside loops. It’s a silent O(n²) performance trap. 🛑 On Day 25, I solved LeetCode 26 and locked in a critical mindset shift: Overwrite, don’t delete. Day 25 — LeetCode 26: Remove Duplicates from Sorted Array Pattern: Two Pointers (Same Direction / Read–Write) Key Insight: Physically deleting elements forces costly shifts. Instead, overwrite “junk” values by copying unique elements forward into a prefix. Everything after the unique count is logically irrelevant. Invariant: nums[0..slow] always contains unique, sorted elements. Outcome: • Solved & submitted — O(n) time, O(1) space • Replaced expensive deletions with pointer-based overwrites • Fixed a common beginner mistake in in-place array problems Question: How do you handle array clean-up when performance matters? Code / Practice: GitHub → https://lnkd.in/du4FcjyK #LeetCode #DSA #TwoPointers #SoftwareEngineering #LearningInPublic
To view or add a comment, sign in
-
-
Day34 of LeetCode Problem Solving Journey Today I continued my solving Find Peak Element on LeetCode ---under the guidance of Prajjal Dhar at REGex Software Services 📝 Problem Summary Task: Find a peak element in an array. Definition: A peak element is one that is strictly greater than its neighbors. Input Example: nums = [1, 2, 3, 1] Output Example: 2 (index of element 3, since it’s greater than both 2 and 1). Constraints: Array length ≥ 1 Multiple peaks may exist, but returning any one valid peak index is acceptable. ⚙️ Solution Approach Method Used: Binary Search (Optimal). Logic: Compare nums[mid] with nums[mid+1]. If nums[mid] < nums[mid+1], move search to the right (left = mid+1). Else, move search to the left (right = mid). Continue until left == right, which gives the peak index. #Day34 #100DayOfLeetCode #ProgramingJourney #KeepGrowing #LeetCode #ProblemSolving #DSA #C++ #LearningWithPrajjalDhar #Regexsoftwareservices
To view or add a comment, sign in
-
-
Day 24 / 100 ✅ 🧠 Today’s focus: LeetCode 234 – Palindrome Linked List Instead of just coding it, I paid attention to the pattern behind it. 🔍 What the problem checks: Can we verify if a linked list reads the same forward and backward? ⚙️ My approach: • Traverse the list and store values in a vector • Use two pointers (start & end) • Compare elements until they meet Simple idea. Clear logic. Accepted successfully. 💡 Key takeaway: Even when a problem can be optimized further (O(1) space using reverse technique), understanding the basic comparison approach strengthens fundamentals first. Not every day needs a complex algorithm. Some days are about reinforcing patterns. 24 days in. Still building discipline. 🚀 #100DaysOfCode #LeetCode #DSA #LinkedList #ProblemSolving #CPlusPlus #Regexsoftware
To view or add a comment, sign in
-
-
#100DaysOfLeetCodeChallenge Day 19/100- LeetCode Challenge 141-LINKED LIST CYCLE. 🧩 Problem Statement Given the head of a linked list, determine whether the list contains a cycle. Used the classic two-pointer technique: 🔹 Slow pointer → moves 1 step at a time 🔹 Fast pointer → moves 2 steps at a time If a cycle exists, both pointers will eventually meet. If fast reaches NULL, there is no cycle. 📚 Key Learnings ✅ Understanding pointer movement deeply ✅ Avoiding infinite loops ✅ Writing safe loop conditions (fast != NULL && fast->next != NULL) ✅ Mastering one of the most important Linked List patterns ⏱ Complexity • Time Complexity: O(n) • Space Complexity: O(1) Consistency in practice is building stronger fundamentals every day 💪 #LeetCode #DSA #LinkedList #FloydAlgorithm #ProblemSolving #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
More from this author
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