Day 45 of #100DaysOfCode: Recursion and Backtracking Challenge

🚀 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

  • graphical user interface, text, application, chat or text message

To view or add a comment, sign in

Explore content categories