🔥 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
PRINCE KUMAR’s Post
More Relevant Posts
-
🔥 Day 171 of My LeetCode Journey Problem 112: Path Sum 💡 Problem Insight: Today’s problem was about checking whether a binary tree has a root-to-leaf path whose sum equals a target value. The key detail here is root-to-leaf — not any path. Missing that leads to wrong answers. 🧠 Concept Highlight: The solution is a clean use of DFS (recursion): Subtract the current node’s value from the target Move to left and right subtrees When you reach a leaf, check if the remaining sum is zero This ensures you explore all valid paths without unnecessary work. 💪 Key Takeaway: Tree problems often reduce to accumulating state along a path. Instead of storing paths, update the condition as you traverse. ✨ Daily Reflection: This problem reinforced how recursion naturally fits tree traversal. Once you think in terms of paths and state, the solution becomes straightforward. #Day171 #LeetCode #BinaryTree #DFS #PathSum #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 216 of #300DaysOfCoding 💡 Solved: Minimum Absolute Distance Between Mirror Pairs (LeetCode 3761) Today’s problem was a great mix of hashing + number manipulation that tested both logic and attention to detail. 🔍 Problem Summary: Given an array, find the minimum distance between indices (i, j) such that: 👉 reverse(nums[i]) == nums[j] and i < j ⚡ Key Insight: Instead of checking all pairs (which would be O(n²)), we optimize using a HashMap. Store reversed values while iterating Check if the current number already exists in the map Update the minimum distance 🧠 What I Learned: Direction of logic matters a lot in hashing problems Small mistakes in mapping can lead to wrong answers Always dry run edge cases like [120, 21] ⏱️ Complexity: Time: O(n) Space: O(n) 🔥 Takeaway: Efficient problem solving is not just about knowing concepts, but applying them in the right direction. Consistency is the real game changer — showing up every single day 💯 #LeetCode #DSA #CodingJourney #PlacementPreparation #SoftwareEngineering #HashMap #ProblemSolving #Consistency #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 37/75 Solved Path Sum III (LeetCode 437) today! 🌳 ✅ All 130/130 test cases passed ⚡ Runtime: 7 ms (Beats ~59%) 💾 Memory: 18.94 MB (Beats ~76%) 🔍 Approach: Used DFS (recursion) to explore all possible paths in the binary tree. ✔️ For each node, calculated cumulative sum along the path ✔️ Checked if the current sum matches the target ✔️ Started fresh DFS from every node to cover all paths ✔️ Counted all valid paths where sum equals target This ensures we consider every possible path efficiently. 💡 Key Learning: Tree problems often require exploring every node as a starting point. Combining recursion with careful state tracking makes solutions more effective. Consistency + practice = better problem solving 🚀 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
To view or add a comment, sign in
-
-
🚀 LeetCode 219 — Contains Duplicate II | Solved ✅ Today I tackled a classic Sliding Window + Hashing problem. 🔍 Problem: Check if there exist two equal elements such that their index difference is at most k. 💡 Approach: Used a sliding window of size k with a hash set to track elements. If an element already exists in the window → duplicate found. ⚡ Complexity: Time: O(n) Space: O(k) ✨ Key Learning: Instead of tracking frequency, sometimes just tracking presence is enough — simplifying both logic and performance. Consistency is the real key 🔑 #LeetCode #DSA #CodingJourney #SlidingWindow #Hashing
To view or add a comment, sign in
-
-
🚀 Day 10/100 — LeetCode Challenge Solved 3Sum The brute force approach is simple: Try all triplets → O(n³) But that’s not scalable. 💡 Optimized Approach: 1) First, sort the array 2) Fix one element 3) Use two pointers to find the remaining pair 👉 This reduces the complexity significantly. Also handled duplicates carefully to avoid repeated triplets. 🧠 Time Complexity: O(n²) 💾 Space Complexity: O(1) (ignoring output) 💡 What I learned: Sometimes optimization is not about complex logic, but about: 1) Sorting 2) Using patterns like two pointers 3) Eliminating unnecessary work This problem felt like a step up from previous ones. Staying consistent. #LeetCode #DSA #100DaysOfCode #Cpp #TwoPointers #CodingJourney
To view or add a comment, sign in
-
-
Day 31/75 🚀 Solved Maximum Twin Sum of a Linked List (LeetCode 2130) today! ✅ All 46/46 test cases passed ⚡ Runtime: 3 ms (Beats ~67%) 💾 Memory: 124.34 MB (Beats ~67%) 🔍 Approach: Converted the linked list into an array for easy access. ✔️ Stored all node values in a vector ✔️ Used two pointers → one at start, one at end ✔️ Calculated twin sum (list[i] + list[n-1-i]) ✔️ Tracked maximum among all pairs This avoids complex pointer manipulation. 💡 Key Learning: Sometimes extra space simplifies logic a lot. Choosing clarity over optimization can be a smart move. Consistency + smart decisions = efficient solutions 💡 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
To view or add a comment, sign in
-
-
🚀 LeetCode 74 — Search a 2D Matrix | Solved with 100% Runtime ✅ Solved this interesting Binary Search problem today! 🔍 Problem Insight: Given a 2D matrix where: • Each row is sorted • First element of each row > last element of previous row 💡 Approach: Used a two-step Binary Search: 1️⃣ First, identify the correct row using binary search 2️⃣ Then, apply binary search within that row ⚡ Time Complexity: O(log m + log n) ≡ O(log(m × n)) ✨ Key Learning: A 2D matrix like this can also be treated as a flattened sorted array, enabling a single binary search approach as well. 📈 Result: 0 ms runtime (Beats 100%) 💯 Consistency + pattern recognition = growth 🚀 Grateful to Pratyush Narain for the guidance and clear explanations. #LeetCode #DSA #BinarySearch #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
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
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 29/50 – LeetCode Challenge 🧩 Problem: Swap Nodes in Pairs Today’s problem focused on swapping nodes of a linked list in pairs, which helped strengthen concepts of pointer manipulation and linked list traversal. 📌 Problem Summary: Given a linked list, swap every two adjacent nodes and return the modified list. You must not modify node values, only change the links. 🔍 Approach Used (My Implementation) ✔ Used a dummy node to handle edge cases easily ✔ Maintained two pointers: prev → points to node before the pair cur → points to the first node of the pair ✔ For each pair: Stored next pair using npn = cur.next.next Identified second node → second = cur.next ✔ Swapped nodes by updating pointers: second.next = cur cur.next = npn prev.next = second ✔ Moved pointers forward: prev = cur cur = npn ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) 💡 Key Learning ✔ Importance of dummy node in linked list problems ✔ Mastering pointer manipulation ✔ Handling edge cases in linked lists ✔ Writing clean and efficient in-place solutions This problem really improved my confidence in working with linked list pointer operations. Consistency builds strong fundamentals 🚀 🔗 Problem Link: https://lnkd.in/gDjVrGur #50DaysOfLeetCode #LeetCode #DSA #LinkedList #ProblemSolving #CodingJourney #FutureAIEngineer #Consistency
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