🌳 Day 73 of #100DaysOfCode 🌳 💡 Problem: Binary Tree Inorder Traversal – LeetCode ✨ Approach: Implemented a recursive inorder traversal to explore the binary tree in Left → Root → Right order. A perfect balance of recursion and logic — the beauty of tree traversal lies in its simplicity 🌿 📊 Complexity Analysis: Time Complexity: O(n)** — visiting each node exactly once Space Complexity: O(n)** — due to recursion stack and list storage ✅ Runtime: 0 ms (🔥 Beats 100%) ✅ Memory: 43.25 MB 🔑 Key Insight: Recursion simplifies complex tree structures into elegant solutions — one node at a time 🌱 #LeetCode #100DaysOfCode #DataStructures #BinaryTree #Recursion #ProblemSolving #DSA #AlgorithmDesign #CodeEveryday #ProgrammerJourney #Java #CodingChallenge
Solved Binary Tree Inorder Traversal with recursion in 100 Days of Code
More Relevant Posts
-
👇 📅 Day 84 of #100DaysOfLeetCode Problem: Find Largest Value in Each Tree Row (LeetCode #515) Approach: The problem requires finding the largest value in each level of a binary tree. This can be efficiently solved using Level Order Traversal (BFS). For each level, store all node values and select the maximum one. Add these maximum values to the result list. Steps: Use a queue to perform level-by-level traversal. For each level, collect node values in a list. Compute the maximum value for that level and add it to the output list. Continue until the queue is empty. Complexity: ⏱️ Time: O(n) — every node is visited once. 💾 Space: O(n) — queue and result storage. 🔗 Problem Link: https://lnkd.in/eQz5GBU8 🔗 Solution Link: https://lnkd.in/eAC_3SwK #LeetCode #100DaysOfCode #BinaryTree #LevelOrderTraversal #BFS #DataStructures #Java #Algorithms #ProblemSolving #DailyCoding #CodingChallenge #BuildInPublic #LearnToCode #SoftwareEngineering
To view or add a comment, sign in
-
-
🌿 Day 74 of #100DaysOfCode 🌿 💡 Problem: Binary Tree Preorder Traversal – LeetCode 🚀 Approach: Used a recursive traversal to explore nodes in the order Root → Left → Right. Preorder traversal is all about visiting the leader first — just like taking the initiative before exploring possibilities! 💫 📊 Complexity Analysis: Time Complexity: O(n)** — every node is visited once Space Complexity: O(n)** — due to recursion stack ✅ Runtime: 0 ms (⚡ Beats 100%) ✅ Memory: 43.06 MB 🔑 Key Insight: Recursion helps untangle even the deepest branches — one root call at a time 🌱 #LeetCode #100DaysOfCode #BinaryTree #Recursion #CodingJourney #DSA #ProblemSolving #Java #Algorithms #ProgrammerLife #WomenInTech #CodeEveryday
To view or add a comment, sign in
-
-
🌳 Day 60 of #100DaysOfCode 🌳 🔹 Problem: Balanced Binary Tree – LeetCode ✨ Approach: Used a post-order DFS traversal to calculate subtree heights while checking balance at every node. If the height difference of any subtree exceeds 1, return -1 immediately for an early exit — efficient and elegant! ⚡ 📊 Complexity Analysis: Time: O(n) — each node visited once Space: O(h) — recursion stack space, where h is the tree height ✅ Runtime: 0 ms (Beats 100%) ✅ Memory: 44.29 MB 🔑 Key Insight: A balanced tree isn’t just about equal heights — it’s about smart recursion that detects imbalance early, saving both time and memory. 🌿 #LeetCode #100DaysOfCode #Java #DSA #BinaryTree #Recursion #ProblemSolving #AlgorithmDesign #CodeJourney #ProgrammingChallenge
To view or add a comment, sign in
-
-
📅 Day 83 of #100DaysOfLeetCode Problem: Lowest Common Ancestor of a Binary Tree (LeetCode #236) Approach: The problem asks to find the lowest common ancestor (LCA) of two nodes in a binary tree. The LCA is the deepest node that has both given nodes as descendants. The approach used: Find the path from the root to each of the two nodes (p and q). Compare both paths node by node until they differ. The last common node before divergence is the LCA. Steps: Use DFS to record paths from the root to p and q. Iterate through both paths to find the common node. Complexity: ⏱️ Time: O(n) — traverses each node at most once. 💾 Space: O(n) — for storing paths. 🔗 Problem Link: https://lnkd.in/dKavVJpA 🔗 Solution Link: https://lnkd.in/dq-Qr2Dm #LeetCode #100DaysOfCode #BinaryTree #Recursion #TreeTraversal #DSA #Java #Algorithms #ProblemSolving #DailyCoding #CodeNewbie #LearnToCode #BuildInPublic
To view or add a comment, sign in
-
-
#98day of #100DaysOfCode 🌿 LeetCode 1302: Deepest Leaves Sum Today’s problem was about exploring the depths of a binary tree 🌳 We needed to find the sum of all the deepest leaf nodes — those that rest at the very bottom of the tree. 🧠 Approach: Two main ways to solve it: 1️⃣ Level Order Traversal (BFS): Traverse level by level; the last level’s sum is the answer. 2️⃣ Depth-first Search (DFS): Track maximum depth and accumulate the sum of deepest nodes. 📈 Complexity: Time: O(n) Space: O(n) 💬 Learning: Whether in trees or life, depth reveals value — the deeper you go, the richer the sum 🌱 #LeetCode #DSA #BinaryTree #CodingChallenge #java #ProblemSolving #LeetCodeDaily #100DaysOfCode #Algorithm
To view or add a comment, sign in
-
-
🚀 116 days of #200DaysOfCode Problem: 113. Path Sum II Problem Statement: Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of the node values. Approach: Used Depth-First Search (DFS) to explore all root-to-leaf paths while tracking the current path and sum. Added valid paths to the result when a leaf was reached and the sum matched the target. Logic: DFS with backtracking efficiently explores all possible paths and ensures only valid ones are stored. This approach is intuitive for tree problems and leverages recursion for clean path management. 👉 Question link 🔗: https://lnkd.in/gEp7MAYW #LeetCode #Java #Tree #DFS #Backtracking #DSA #Coding #Algorithms #InterviewPrep #200DaysOfCode
To view or add a comment, sign in
-
-
Day 41 — DSA From Scratch Today's problem: Binary Tree Inorder Traversal The task was to return the inorder traversal of a binary tree — visiting nodes in the order Left → Root → Right. Approach Used: Used a simple recursive approach — Traverse the left subtree. Visit and record the current node’s value. Traverse the right subtree. This approach naturally follows the definition of inorder traversal and helps in understanding tree recursion better. Time Complexity: O(n) — each node is visited once. Space Complexity: O(h) — where h is the height of the tree (recursion stack). Another small step in getting comfortable with recursion and binary tree fundamentals. #Day41 #DSAFromScratch #100DaysOfCode #BinaryTrees #LeetCode #ProblemSolving #Java #Recursion #DataStructures #LearningEveryday #Consistency
To view or add a comment, sign in
-
-
📌 Day 21/100 – Sort an Array (LeetCode 912) 🔹 Problem: Given an integer array, sort it in ascending order without using built-in sorting functions and ensure the solution runs in O(n log n) time. 🔹 Approach (Merge Sort): Divide the array into two halves recursively Sort each half independently Merge the two sorted halves while maintaining order Uses Divide & Conquer and guarantees stable sorting 🔹 Key Learnings: Merge Sort ensures worst-case O(n log n) time unlike QuickSort Works well for linked lists & large datasets because of stability Uses extra space due to temporary list merging Great example of recursion + two-pointer merging technique #100DaysOfCode #Day21 #LeetCode #Java #DSA #MergeSort #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
✅ Just solved LeetCode #654 — Maximum Binary Tree 📘 Problem: Given an integer array without duplicates, the task is to build a maximum binary tree. The construction rules are: 1️⃣ The root is the maximum element in the array. 2️⃣ The left subtree is built recursively from elements to the left of the maximum. 3️⃣ The right subtree is built recursively from elements to the right of the maximum. Example: Input → [3,2,1,6,0,5] Output → [6,3,5,null,2,0,null,null,1] 🧠 My Approach: I solved this problem using a recursive divide-and-conquer approach. 1️⃣ Find the index of the maximum element in the given range — this becomes the root. 2️⃣ Recursively build the left subtree from the subarray before the maximum element. 3️⃣ Recursively build the right subtree from the subarray after the maximum element. 💡 What I Learned: ✅ How recursion naturally fits into tree construction problems ✅ The concept of divide and conquer applied to array-based tree building ✅ How to translate problem definitions into direct recursive structure #LeetCode #Java #DSA #BinaryTree #CodingUpdate #LearningByDoing
To view or add a comment, sign in
-
-
🚩 Problem: 169. Majority Element 🔥 Day 43 of #100DaysOfLeetCode 🔍 Problem Summary: Given an array nums, find the element that appears more than ⌊ n/2 ⌋ times. You may assume that the majority element always exists in the array. ✅ Approach 1: Using HashMap Count the frequency of each element using a HashMap and return the one that occurs most frequently. ✅ Approach 2 (Optimized): Boyer–Moore Voting Algorithm Maintain a candidate and count. Traverse the array: If count == 0, set candidate = num. If num == candidate, increment count, else decrement. Return the candidate. 📊 Complexity: Time Complexity: O(n) Space Complexity: O(1) ✨ Key Takeaway: The Boyer–Moore Voting Algorithm is a brilliant example of how a deep understanding of problem constraints can lead to an O(1) space solution — an essential pattern in algorithmic thinking. Link:[https://lnkd.in/gsc4XgbK] #100DaysOfLeetCode #Day43 #Problem169 #MajorityElement #BoyerMoore #Algorithms #DSA #Java #CodingChallenge #ProblemSolving #LeetCode #InterviewPreparation #DataStructures #TechCareers #ArjunInfoSolution #CodingCommunity #CodeNewbie #SoftwareEngineering #ZeroToHero #LearnToCode
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