🔗 Day 75 of #100DaysOfCode 🔗 🌳 Problem: Binary Tree Postorder Traversal – LeetCode ✨ Approach: Implemented a recursive depth-first traversal that processes the left subtree, then right subtree, and finally the root node — perfectly matching the postorder pattern (Left → Right → Root). The solution is clean, intuitive, and highlights the elegance of recursion in tree traversal! 🌿 📊 Complexity Analysis: ⏱ Time Complexity: O(n) — each node is visited exactly once 💾 Space Complexity: O(n) — recursion stack in the worst case (skewed tree) ✅ Runtime: 0 ms (Beats 100% 🚀) ✅ Memory: 43.07 MB 💡 Key Insight: Recursion beautifully mirrors the natural hierarchy of trees — by trusting the call stack, we achieve simplicity and clarity in solving even complex traversal problems. 🌱 #LeetCode #100DaysOfCode #ProblemSolving #DSA #BinaryTree #Recursion #AlgorithmDesign #CodeJourney #ProgrammingChallenge #LogicBuilding #Efficiency #CodingDaily
"Implemented postorder binary tree traversal with recursion"
More Relevant Posts
-
🔹 Problem: Binary Tree Inorder Traversal Day 122 🔹 Difficulty: Easy 🔹 Topic: Binary Tree / Morris Traversal / Iterative Traversal 🔍 Problem Breakdown: We are given the root of a binary tree, and we need to return the inorder traversal of its nodes’ values. 📘 Inorder Traversal: Left → Root → Right Usually, this can be solved using recursion or stack, but today’s approach uses Morris Traversal, which is O(1) extra space and does not use recursion or stack. 🧠 Approach (Morris Traversal): Start with the current node = root. If the left child is NULL, visit the node and move right. Else, find the inorder predecessor (rightmost node in the left subtree). If predecessor’s right is NULL, make a temporary link to the current node and move left. If predecessor’s right is current, remove the link, visit current node, and move right. Continue until all nodes are visited. This method avoids recursion and stack by establishing temporary links in the tree. ⏱️ Time & Space Complexity: Time Complexity: O(n) — each edge is visited twice. Space Complexity: O(1) — no recursion or stack used. 💡 Key Insight: Morris Traversal is a brilliant way to traverse binary trees in constant space, by cleverly using tree links as temporary pointers — elegant and efficient! #LeetCode #DSA #BinaryTree #MorrisTraversal #InorderTraversal #ProblemSolving #CodingChallenge #200DaysOfCode #Cplusplus
To view or add a comment, sign in
-
-
🔍 Day 66 of #100DaysOfCode 🔍 🔹 Problem: Binary Search – LeetCode ✨ Approach: Implemented an iterative binary search to efficiently locate the target element within a sorted array. By halving the search range each time — adjusting low and high around the mid-point — the algorithm achieves blazing-fast lookups! ⚡ 📊 Complexity Analysis: Time Complexity: O(log n) — array size halves with each iteration Space Complexity: O(1) — constant extra space ✅ Runtime: 0 ms (Beats 100.00%) ✅ Memory: 46.02 MB 🔑 Key Insight: Binary Search is proof that efficiency isn’t about doing more — it’s about eliminating what’s unnecessary. 🚀 #LeetCode #100DaysOfCode #ProblemSolving #DSA #AlgorithmDesign #BinarySearch #LogicBuilding #Efficiency #ProgrammingChallenge #CodeJourney #CodingDaily
To view or add a comment, sign in
-
-
🔥 HyperRevision with Structure – Day 88 🔥 🧩 Problem solved today: 1️⃣ Graph Valid Tree (LeetCode 261) 💭 Thoughts: This problem helped me understand what actually makes a graph a tree — it needs to be connected and have no cycles. Really important concept for graph foundations; I think it’ll help a lot in the advanced graph problems later. ⏱️ Time Complexity: O(V + E) 💾 Space Complexity: O(V + E) 📌 GitHub link in comments #HyperRevision #NeetCode150 #GraphTraversal
To view or add a comment, sign in
-
-
🚀 Day 83 | Trees & Structural Matching Today’s problem focused on verifying if one binary tree is a subtree of another — a great blend of recursion, structure comparison, and logic. 🧩 Problem Solved: 572. Subtree of Another Tree • Approach: Used recursion — for each node in the main tree, checked if the subtree starting at that node matched the given subtree using a helper comparison function. • Insight: Tree problems teach the art of recursion — breaking complex hierarchies into repeatable subproblems. ✨ Key Takeaway: Recursion builds clarity — by trusting smaller calls to do their part, big problems become manageable. 📚 Topics: Binary Tree · Recursion · DFS · Comparison Logic 💻 Platform: LeetCode #DSA #LeetCode #ProblemSolving #DailyCoding #BinaryTree #Recursion #DFS #Consistency
To view or add a comment, sign in
-
-
🚀LeetCode Daily Challenge 🧩 Problem: Number of Substrings With Only 1s Problem Intuition: You are given a binary string s. Your task is to count how many non-empty substrings contain only ‘1’s. A key observation is that every continuous segment of 1s contributes multiple substrings. For a segment of length k, the number of substrings formed is: k⋅(k+1)2\frac{k \cdot (k + 1)}{2}2k⋅(k+1)For example, "1" → 1 substring "11" → 3 substrings ("1", "1", "11") "111" → 6 substrings So the goal is to find all consecutive blocks of 1s, compute their contributions, and sum them modulo 109+710^9 + 7109+7. Example Insight: Let’s take an example: s = "110111" Segments: "11" → length = 2 → contributes 3 substrings "111" → length = 3 → contributes 6 substrings Total = 9 substrings that contain only 1s. Approach & Strategy: ✔ Traverse the string and count the length of every consecutive sequence of '1'. ✔ Whenever you hit a '0' or reach the end: • Compute contribution using k(k+1)2\frac{k(k+1)}{2}2k(k+1) • Add to the answer modulo 109+710^9 + 7109+7. ✔ Reset counter and continue. This approach efficiently handles very large strings. 📈 Complexity Analysis: Time Complexity: O(n) — single linear scan Space Complexity: O(1) — constant auxiliary space 🔗 Problem: https://lnkd.in/daKkzfTM 💻 Solution: https://lnkd.in/dReTB6Ab #LeetCode #DSA #Cpp #Strings #Mathematics #ProblemSolving #CodingChallenge #LeetCodeDailyChallenge
To view or add a comment, sign in
-
🎯 LeetCode Daily – Triangle (Day 113) Today’s problem deepened my understanding of Dynamic Programming on Triangular Grids, focusing on minimizing path sums efficiently. ✅ My Approach: 🔹 Problem – Triangle: • The goal was to find the minimum path sum from the top to the bottom of a triangle array. • Used Memoization (Top-Down DP) to recursively explore all paths while storing intermediate results to avoid redundant computations. • Implemented Tabulation (Bottom-Up DP) to build the solution iteratively starting from the last row and moving upward, computing the minimum path for each position using values from the row below. 🧠 Key Insight: This problem beautifully demonstrates the power of Dynamic Programming in optimizing recursive solutions. By transitioning from memoization to tabulation, the problem transforms from exponential recursion to an elegant linear-time solution. Recognizing overlapping subproblems and optimal substructure patterns is key to mastering DP on grids and triangles. 📊 Time Complexity: O(N²) 📦 Space Complexity: O(N²) #LeetCode #DSA #DynamicProgramming #ProblemSolving #DailyCoding #LearningInPublic #Day113
To view or add a comment, sign in
-
-
🎯 Day 81 of #100DaysOfCode 🎯 🔹 Problem: Reverse Only Letters – LeetCode ✨ Approach: Used a two-pointer strategy to reverse only the alphabetic characters while keeping all non-letter characters in their original positions. By moving pointers inward and swapping only when both characters are letters, the solution stays efficient and elegant! 🔄✨ 📊 Complexity Analysis: ⏱ Time Complexity: O(n) — each character visited at most once 💾 Space Complexity: O(n) — due to character array construction ✅ Runtime: 0 ms (Beats 100% 🚀) ✅ Memory: 42.96 MB 🔑 Key Insight: Sometimes, all you need is smart pointer movement — not everything needs to be reversed, only the right pieces. #LeetCode #100DaysOfCode #DSA #TwoPointers #StringManipulation #ProblemSolving #CleanCode #AlgorithmDesign #CodingChallenge
To view or add a comment, sign in
-
-
🔥 HyperRevision with Structure – Day 90 🔥 🧩 Problem solved today: 1️⃣ Redundant Connection (LeetCode 684) 💭 Thoughts: Concept almost similar to Valid Graph Tree. The complexity is O(N²) since the for loop takes another O(N). Not the most optimal solution, but it works. ⏱️ Time Complexity: O(N²) 💾 Space Complexity: O(N) 📌 GitHub link in comments #HyperRevision #NeetCode150 #GraphTraversal
To view or add a comment, sign in
-
-
🔹 Day 74 of #100DaysOfLeetCodeChallenge 🔹 🚀 Problem: Next Greater Element II 🔑 Topic: Stack + Circular Array 🧠 Approach: We need to find the next greater element for each item in a circular array. Here’s the logic 👇 Use a monotonic stack to store indices of elements (in decreasing order). Traverse the array twice (2 × n) to simulate circular behavior. Whenever the current element is greater than the element at the stack’s top, pop it and record the next greater value. Push the index during the first pass only. Default all elements to -1 (in case no greater element exists). ⏳ Time Complexity: O(n) 💾 Space Complexity: O(n) 📌 Example: Input: nums = [1,2,1] Output: [2, -1, 2] ✅ 🎯 Takeaway: Monotonic stacks are super efficient for "next greater" problems — linear time, no brute force, and elegant logic! ⚡ #LeetCode #DSA #Stack #MonotonicStack #ProblemSolving #CodingChallenge #100DaysOfLeetCodeChallenge 🚀
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