🚀 Day 45 of #100DaysOfCode — Leetcode + HackerRank Edition! Today’s challenge was a deep dive into recursion and backtracking 🔁🧠 🧩 permute(self, nums: List[int]) -> List[List[int]] — Generate all possible permutations of a list of distinct integers. 📌 Challenge: → Given a list nums, return all possible orderings → Each number must appear exactly once per permutation → Example: nums = [1, 2, 3] ✅ Output: [[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]] 🔍 Approach: → Use recursion to build permutations step-by-step → Track current path with curr → Skip numbers already in curr → When len(curr) == len(nums), add a copy to results → Backtrack by popping the last element 💡 What made it click: → Visualized the recursive tree — each level adds one unused number → Practiced dry runs with nums = [1, 2, 3] to see how paths evolve → Realized how curr.pop() resets the state for the next branch → Appreciated how backtracking avoids duplicate paths and keeps memory clean 📚 What I learned: ✅ How to implement recursive backtracking with minimal state ✅ How to use dry runs to trace recursive calls ✅ How to visualize tree-like expansion of choices ✅ The power of copying lists (curr[:]) to preserve snapshots Have you ever visualized recursion like a decision tree? Let’s swap strategies and dry run walkthroughs 💬 #Day45 #Leetcode #Python #Recursion #Backtracking #DryRun #LearnInPublic #CodeNewbie #TechJourney #100DaysOfCode #DSA
Day 45 of #100DaysOfCode: Recursion and Backtracking Challenge
More Relevant Posts
-
🚀 Day 46 of #100DaysOfCode — Leetcode + HackerRank Edition! Today’s challenge was a twist on yesterday’s recursion puzzle — this time with duplicates in the mix 🔁🧠 🧩 permuteUnique(self, nums: List[int]) -> List[List[int]] — Generate all unique permutations of a list that may contain duplicate integers. 📌 Challenge: → Given a list nums, return all distinct orderings → Each number must appear exactly once per permutation → Example: nums = [1, 1, 2] ✅ Output: [[1,1,2], [1,2,1], [2,1,1]] 🔍 Approach: → Sort the input to group duplicates → Use recursion + backtracking to build paths → Track visited indices with a used[] array → Skip duplicates using: if i > 0 and nums[i] == nums[i - 1] and not used[i - 1]: continue → Backtrack by popping the last element and resetting used[i] 💡 What made it click: → Visualized the decision tree for [1, 1, 2] — saw how pruning avoids duplicate branches → Practiced dry runs to trace how used[] and sorting work together → Realized how skipping nums[i] when nums[i] == nums[i-1] and used[i-1] == False prevents redundant paths → Appreciated how recursion + pruning = clean, efficient, elegant 📚 What I learned: ✅ How to handle duplicates in permutation problems ✅ How sorting + index tracking helps prune recursion ✅ How to visualize branching decisions and avoid redundant paths ✅ The subtle power of used[] and index-based duplicate checks Have you ever debugged a recursive tree with duplicate values? Let’s swap strategies, dry runs, and visual walkthroughs 💬 #Day46 #Leetcode #Python #Recursion #Backtracking #DryRun #LearnInPublic #CodeNewbie #TechJourney #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
🚀 Day 26 of #100DaysOfCode — LeetCode + HackerRank Edition! Today’s challenge was all about string precision and pattern matching: 🔗 Implement strStr() (LeetCode) 📌 Challenge: Given two strings haystack and needle, return the index of the first occurrence of needle in haystack, or -1 if it doesn’t exist. 🔍 Approach: → Skipped the built-in .find() to implement it manually → Iterated through haystack only up to len(haystack) - len(needle) → Compared slices haystack[i:i+len(needle)] with needle → Returned the index on match, -1 otherwise 💡 What made it click: → Realized that checking every possible starting index is enough — no need to build substrings manually → Adjusting the loop range to avoid out-of-bound errors was the key → Removing redundant checks like if needle not in haystack made the code cleaner and faster 📚 What I learned: ✅ Substring search is a great intro to sliding window logic ✅ Clean loop bounds = fewer bugs ✅ Sometimes the simplest approach is the most elegant ✅ Writing your own version of built-ins deepens your understanding of how they work under the hood Have you implemented your own strStr() before? Did you go brute-force or try KMP? Let’s compare strategies 💬🔍 #Day26 #LeetCode #StringMatching #CodingChallenge #Python #ProblemSolving #CleanCode #CodeEveryDay #LearnToCode #CodeNewbie #SoftwareEngineering #TechJourney #geeksforgeeks #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 52 of #100DaysOfCode — Leetcode + HackerRank Edition! Today’s challenge was all about bringing order to chaos — merging overlapping intervals into clean, non-overlapping ranges 🗂️✨ 🧩 def merge(self, intervals: List[List[int]]) -> List[List[int]]: — Combine overlapping intervals into a simplified list 📌 Challenge: → Implement a function to merge overlapping intervals → Avoid brute-force approaches that check every pair → Optimize for clarity and performance 🔍 Approach: → First, sort intervals by their start time → Keep track of the last merged interval (prev[0]) → If the current interval overlaps, extend the end boundary → Otherwise, add it as a new interval 💡 What made it click: → Realized sorting upfront makes merging straightforward → Saw how prev[1] = max(prev[1], interval[i][1]) elegantly handles overlaps → Practiced dry runs with examples like: [[1,3],[2,6],[8,10],[15,18]] → [[1,6],[8,10],[15,18]] 📚 What I learned: ✅ Why sorting is the key to simplifying interval problems ✅ How greedy merging avoids unnecessary comparisons ✅ How to handle edge cases like single intervals or fully nested ranges Ever felt like your calendar was a mess of overlapping meetings? This algorithm is the perfect organizer 🗓️😎 Let’s swap dry runs, edge cases, and interval insights 💬 #Day51 #Leetcode #Python #MergeIntervals #GreedyAlgorithm #DryRun #LearnInPublic #CodeNewbie #TechJourney #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
🚀 Day 41 of #100DaysOfCode — Leetcode + HackerRank Edition! Today’s challenge was a twist on yesterday’s recursive puzzle — this time with stricter rules and smarter pruning: 🧩 combinationSum2(candidates, target) — Find all unique combinations that sum to a target, using each number only once. 📌 Challenge: Given a list of positive integers, return all combinations that add up to a target. → Each number can be used once per combination → Combinations must be unique (no duplicates in different orders) → Example: candidates = [10,1,2,7,6,1,5], target = 8 ✅ Output: [[1,1,6],[1,2,5],[1,7],[2,6]] 🔍 Approach: → Sorted the input to handle duplicates cleanly → Used a recursive helper with backtracking → Skipped repeated values at the same recursive level → Moved to the next index after choosing a candidate (no reuse!) 💡 What made it click: → Realized that i > start and candidates[i] == candidates[i - 1] is the key to skipping duplicates → Practiced dry runs to see how [1,2,5] gets built and why [1,2,5] doesn’t repeat → Saw how index control + pruning = clean and efficient recursion → Appreciated how path.pop() lets us rewind and explore new paths 📚 What I learned: ✅ How to implement backtracking with recursion ✅ How to avoid duplicate combinations using sorted input and index checks ✅ How to prune invalid paths early for performance ✅ The elegance of recursive tree exploration Have you tackled this one before? Did you use recursion or dynamic programming? Let’s swap strategies 💬 #Day40 #Leetcode #Python #Backtracking #RecursionChallenge #LearnInPublic #CodeNewbie #TechJourney #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
🚀 Day 51 of #100DaysOfCode — LeetCode + HackerRank Edition Today’s challenge: Spiral Matrix — traverse a matrix in spiral order and return the elements. 🌀🧩 Problem (brief): Given an m x n matrix, return all elements in spiral order (clockwise starting from top-left). 📌 My approach →Use four boundaries: top, bottom, left, right. →Walk: left→right along top, top→bottom along right, right→left along bottom, bottom→top along left. →After each traversal, move the corresponding boundary inward. →Repeat while top <= bottom and left <= right. →Handle edge cases: single row, single column, or empty matrix. 💡 What I learned today: ✅Boundary-driven traversal is a neat pattern — useful for many matrix problems. ✅Always check the top<=bottom and left<=right conditions before traversing opposite sides to avoid duplicates. ✅Dry runs are everything — they reveal off-by-one bugs faster than tests. Let’s share patterns — how do you solve Spiral Matrix? Do you prefer boundary pointers, or recursion (peel the outer layer)? Drop your implementation or edge cases — I’ll compare notes! 👇 #Day51 #100DaysOfCode #LeetCode #Python #DSA #SpiralMatrix #ProblemSolving #CodeNewbie #LearnInPublic
To view or add a comment, sign in
-
🚀 Day 33 of #100DaysOfCode — LeetCode + HackerRank Edition! Today’s challenge was a classic twist on binary search — searching in a rotated sorted array. 🔗 Problem: search(self, nums: List[int], target: int) (LeetCode) 📌 Challenge: Given a rotated sorted array, find the index of a target value in O(log n) time. 🔍 Approach: → Used binary search with a twist: at each step, determined which half of the array is sorted → If the left half is sorted, checked if the target lies within it → If not, searched the right half — and vice versa → Carefully updated low, high, and recalculated mid inside the loop → Avoided brute-force by leveraging the sorted structure of one half at every step 💡 What made it click: → Realized that one half is always sorted, even after rotation → Visualized the array and dry-ran examples like [4,5,6,7,0,1,2] to understand the logic → Fixed a key bug: I was calculating mid only once — moving it inside the loop made everything work! → Debugging this helped me appreciate how small details (like mid placement) can make or break binary search 📚 What I learned: ✅ Binary search can be adapted to rotated arrays with clever logic ✅ Always recalculate mid after updating low and high ✅ Dry runs are powerful for catching logic bugs Have you tackled rotated binary search before? Did you use recursion, iteration, or something else? Let’s swap strategies 💬 #Day33 #LeetCode #BinarySearch #RotatedArray #ProblemSolving #Python #DebuggingJourney #CleanCode #LearnToCode #CodeNewbie #SoftwareEngineering #TechJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 32 of #100DaysOfCode — LeetCode + HackerRank Edition! Today’s challenge was all about frequency mapping and subarray logic — solving the Picking Numbers problem from HackerRank. 🔗 Problem: pickingNumbers(a) (HackerRank) 📌 Challenge: Given an array of integers, find the length of the longest subarray where the absolute difference between any two elements is ≤ 1. 🔍 Approach: → Used Python’s Counter to map frequencies of each number → For each number num, calculated freq[num] + freq[num + 1] → Tracked the maximum such sum to find the longest valid subarray → Avoided brute-force by leveraging frequency patterns instead of scanning all subarrays 💡 What made it click: → Realized that valid subarrays must contain only num and num + 1 → Frequency mapping reveals hidden structure in the data → Clean logic with max() and get() made the solution elegant and readable 📚 What I learned: ✅ Frequency-based thinking can simplify subarray problems ✅ Counter is a powerful tool for pattern detection ✅ Avoiding brute-force leads to scalable, efficient solutions ✅ Sharing dry runs and visual walkthroughs helps others grasp the intuition faster Have you tackled Picking Numbers before? Did you go with sorting, brute-force, or frequency mapping like I did? Let’s swap strategies 💬 #Day31 #HackerRank #SubarrayLogic #FrequencyMapping #Python #ProblemSolving #CleanCode #CodeEveryDay #LearnToCode #CodeNewbie #SoftwareEngineering #TechJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 29 of #100DaysOfCode — LeetCode + HackerRank Edition! Today’s challenge was all about precision and pattern matching — and I stuck to the essentials. 🔗 Problem: findSubstring(s, words) (LeetCode) 📌 Challenge: Given a string s and a list of words (all the same length), find all starting indices where the concatenation of all words appears exactly once and without overlap. 🔍 Approach: → Calculated the total length of the target substring using len(words[0]) * len(words) → Built a frequency map using Counter(words) → Used a sliding window of size total_len to scan through s → At each position, extracted word-sized chunks and tracked their frequency → Compared the seen map with the original word_count to validate matches → Appended valid starting indices to the result list 💡 What made it click: → Realized that permutations aren’t necessary — just match word frequencies → Stepping through s in word-sized chunks keeps the logic clean and efficient → Using Counter for both the target and current window made comparison seamless 📚 What I learned: ✅ Frequency maps are a powerful alternative to brute-force approaches ✅ Matching dictionaries directly (seen == word_count) is a validation trick ✅ Clean logic and early breaks make the code both readable and performant Have you solved findSubstring before? Did you go with permutations or lean into frequency maps like I did? Let’s swap strategies 💬 #Day29 #LeetCode #SlidingWindow #StringAlgorithms #Python #ProblemSolving #CleanCode #CodeEveryDay #LearnToCode #CodeNewbie #SoftwareEngineering #TechJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 36 of #100DaysOfDSA Solved LeetCode Problem #39 – Combination Sum 🔢✨ 📌 Problem Insight: Given a set of distinct integers and a target number, the task is to find all unique combinations of numbers that add up to the target. Each number can be used multiple times. A great problem to strengthen backtracking and recursion concepts. 💡 Key Learnings: Practiced backtracking to explore all valid combinations. Understood how to reuse elements by controlling the recursive index. Learned efficient pruning — stop recursion when sum exceeds the target. Time complexity: O(2ⁿ) (since all paths are explored). Space complexity: O(target) (recursion stack). 📌 Approach (short): Use recursion to explore every combination. If sum equals target → store it. If sum exceeds target → backtrack. Continue exploring remaining candidates. 👉 Backtracking problems teach patience and logic — finding all valid paths one step at a time 🚀 #LeetCode #DSA #ProblemSolving #100DaysChallenge #Day36 #CodingJourney #Python #Backtracking
To view or add a comment, sign in
-
-
🚀 Day 4/100 — Cracked LeetCode 1611: Minimum One Bit Operations to Make Integers Zero 🔥 Today’s challenge was a deep dive into bit manipulation and recursion. LeetCode 1611 looked deceptively simple—but beneath the surface, it’s a clever twist on Gray code transformations. 🔍 Problem Summary Transform an integer n into 0 using two constrained bit-flipping operations. The trick? You can only flip the rightmost bit, or flip the i-th bit if the (i-1)th is 1 and all lower bits are 0. 🧠 Key Insight This problem maps beautifully to recursive Gray code logic. For any number n, we recursively reduce it by flipping the highest set bit and subtracting the operations needed for the remainder. 📈 What I Learned Bitwise recursion can be elegant and powerful. Understanding binary patterns unlocks optimization. Python’s bit_length() is a hidden gem for bit-level logic. 🔧 Next Steps I’ll be documenting more of these insights as part of my 100-day challenge. If you’re into algorithmic puzzles or want to collaborate on clean, modular solutions—let’s connect! #100DaysOfCode #LeetCode #Python #BitManipulation #GrayCode #CodingChallenge #TechJourney #ScarBuilds
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
keep grinding champ :)