💻 Day 4 of #100DaysOfCode Challenge Topic: Binary Tree Traversals 🌳 Problems Solved: 🔹 94. Binary Tree Inorder Traversal 🔹 144. Binary Tree Preorder Traversal 🔹 145. Binary Tree Postorder Traversal Concept Recap: Today, I explored the three fundamental depth-first traversal techniques used in binary trees: ✅ Inorder (Left → Root → Right) – Produces a sorted order for BSTs. ✅ Preorder (Root → Left → Right) – Useful for creating a copy of the tree or serialization. ✅ Postorder (Left → Right → Root) – Ideal for deleting trees or evaluating expressions. Each traversal follows a recursive approach to explore nodes systematically. Implementing them helped me strengthen my understanding of recursion and how stack frames manage function calls behind the scenes. Key Learnings: 🧠 Understood how traversal order impacts output sequence. ⚙️ Practiced recursive depth-first traversal logic in Java. 🌱 Improved code readability by modularizing recursive functions. #LeetCode #DataStructures #BinaryTree #Recursion #Java #CodingChallenge #100DaysChallenge #Day4
Mastering Binary Tree Traversals with #100DaysOfCode Challenge
More Relevant Posts
-
💻 Day 75 of #100DaysOfCodingChallenge ✨ Problem: 560. Subarray Sum Equals K 📚 Category: Array Manipulation | Subarray Problems 💡 Approach: Brute Force 🧠 Language: Java 🔍 Problem Understanding: We’re given an integer array nums and an integer k. We need to count how many subarrays (continuous parts of the array) have a sum equal to k. Example: Input: nums = [1, 2, 3], k = 3 Output: 2 Explanation: [1,2] and [3] are the subarrays with sum 3. 🧠 Brute Force Approach: In the brute-force method, we check every possible subarray using two loops: 1️⃣ Start from each element as a subarray beginning. 2️⃣ Keep adding elements until the end, and check if the sum equals k. 3️⃣ If yes, increment the count. Although it’s not the most optimized, this approach helps build a strong foundation in understanding subarray logic. ⚙️ Complexity: Time Complexity: O(n²) Space Complexity: O(1) 🌱 Learning: This problem taught me how to approach subarray-based questions step-by-step — starting from brute force before moving toward optimized solutions like prefix sums + hashmaps. Building clarity in fundamentals always makes optimization easier later 🚀 #Day75 #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney #WomenInTech #DSA #ArrayManipulation
To view or add a comment, sign in
-
-
🚀 Day 14 — Data Structures & Algorithms in Java 🔹 Topic: First Unique Character in a String (Using HashMap) Today, I explored how to identify the first non-repeating character in a given string using HashMap — an efficient and flexible approach that works for all character types. 💡 Concept We store each character’s frequency in a HashMap, then find the first index with frequency 1. 🧠 Example 📥 Input: "loveleetcode" 📤 Output: 2 (Character 'v' is the first unique one) ⚙️ Complexity ⏱ Time: O(n) 💾 Space: O(n) ✨ Key Takeaway HashMaps are incredibly powerful for frequency-based problems — offering both simplicity and efficiency in solving string and array challenges. #Java #Coding #30DaysOfCode #LeetCode #DSA #ProblemSolving #LearningJourney #WomenInTech #1000coders
To view or add a comment, sign in
-
-
🚀 Day 60 of #100DaysOfCode 🚀 Today, I solved LeetCode Problem #137 – Single Number II 🧩 📘 Problem Statement: Given an integer array where every element appears three times except for one that appears exactly once, find that single element and return it. The challenge: solve it with O(n) time and O(1) space complexity. 💻 Language: Java ⚡ Runtime: 0 ms — Beats 100.00% 📉 Memory: 45.54 MB — Beats 56.30% 🧠 Concept Used: 🔹 Bit Manipulation — A powerful yet tricky technique that leverages binary operations to track occurrences of bits efficiently. 🔹 Instead of using extra space or hash maps, we track bits that appear once and twice using two integer variables: ✅ once → bits that appeared once ✅ twice → bits that appeared twice The trick lies in updating them using XOR (^) and NOT (~) to "cancel out" bits appearing three times. 🧩 Approach Summary: 1️⃣ Initialize two variables once = 0 and twice = 0. 2️⃣ For every number in the array: - Update once and twice based on how many times a bit has appeared. 3️⃣ After processing all numbers, once holds the value of the single element. ✅ Complexity: Time: O(n) Space: O(1) ✨ Takeaway: This problem teaches how bitwise logic can replace traditional data structures, achieving the same result with constant space — a crucial optimization in system-level programming and interviews. #100DaysOfCode #LeetCode #Java #BitManipulation #ProblemSolving #CleanCode #DataStructures #Algorithms #TechLearning #CodingChallenge #SoftwareEngineering #InterviewPreparation
To view or add a comment, sign in
-
-
🌳 Day 65 of #LeetCode Journey 🔹 Problem: 106. Construct Binary Tree from Inorder and Postorder Traversal 🔹 Difficulty: Medium 🔹 Language: Java Today’s problem is about rebuilding a binary tree when you’re given its inorder and postorder traversal arrays. 🧩 Key Idea: The last element in postorder is always the root. In inorder traversal, elements to the left of the root are in the left subtree, and elements to the right are in the right subtree. We recursively build the tree using this property. 💡 Approach: Start from the end of the postorder array to get the root. Use a hashmap to store inorder indices for O(1) lookup. Recursively construct the right subtree first, then the left subtree (since we’re moving backward in postorder). 🧠 Concepts reinforced: Recursion HashMap for index lookup Understanding inorder & postorder relationships 🔥 Another step forward in mastering tree construction problems! #LeetCode #100DaysOfCode #Java #CodingChallenge #DataStructures #BinaryTree #Recursion #ProblemSolving #ProgrammingJourney
To view or add a comment, sign in
-
-
💡 Day 31/100 Days Today’s problem was “Valid Palindrome” 🪞 The challenge was to check if a string reads the same forward and backward after removing all non-alphanumeric characters and ignoring case differences. This helped strengthen my understanding of string manipulation and the two-pointer technique in Java. 🧠 Key Features: Cleaned the string using regex to remove unwanted characters. Applied two-pointer logic to compare characters from both ends. Simple, efficient, and elegant — a great example of how logic matters more than length of code. ⚙️ Time Complexity: O(n) → Each character checked once. 💾 Space Complexity: O(n) → For the cleaned string (or O(1) in in-place approach). ✨ Takeaway: This problem reinforced how small optimizations — like using pointers instead of extra data structures — make algorithms more efficient. Every problem is a step closer to cleaner and smarter code! #Day31Of100 #DSA #Java #ProblemSolving #TwoPointer #CodingJourney #100DaysOfCode #LearningEveryday
To view or add a comment, sign in
-
-
📅 Day 81 of #100DaysOfLeetCode Problem: Insert into a Binary Search Tree (LeetCode #701) Approach: The task is to insert a new node with a given value into a Binary Search Tree (BST). Start from the root and recursively find the correct position: If the new value is smaller than the current node’s value, go to the left subtree. Otherwise, go to the right subtree. When a null spot is found, insert a new node there. The BST property is preserved throughout this process. Complexity: ⏱️ Time: O(h) — where h is the height of the tree. 💾 Space: O(h) — recursive call stack. 🔗 Problem Link: https://lnkd.in/dCS7zxVG 🔗 Solution Link: https://lnkd.in/dxB4ZNtV #LeetCode #100DaysOfCode #BinarySearchTree #Recursion #Java #TreeTraversal #DSA #Algorithms #CodingChallenge #ProblemSolving #CodeNewbie #StudyWithMe #BuildInPublic #LearnToCode #DailyCoding
To view or add a comment, sign in
-
-
💻 Day 53 of #100DaysOfCode 💻 Today, I solved LeetCode Problem #709 – To Lower Case 🔠 This problem focuses on string manipulation and character encoding (ASCII values) — one of the simplest yet fundamental concepts in text processing. 💡 Key Learnings: Reinforced understanding of ASCII value ranges for uppercase and lowercase alphabets. Practiced efficient string traversal and conditional conversion using StringBuilder in Java. Time complexity: O(n) — iterates through the string once. Space complexity: O(n) — for the output string. 💻 Language: Java ⚡ Runtime: 0 ms — Beats 100% 🚀 📉 Memory: 41.78 MB — Beats 43.48% 🧠 Approach: 1️⃣ Iterate through each character in the string. 2️⃣ Check if it’s an uppercase letter (A–Z). 3️⃣ Convert it to lowercase by adding 32 (based on ASCII values). 4️⃣ Append to the final string using StringBuilder. ✨ Takeaway: Sometimes, understanding the basics like ASCII values can help you write your own efficient methods — without relying on built-in functions! #100DaysOfCode #LeetCode #Java #CodingChallenge #ProblemSolving #Algorithms #StringManipulation #SoftwareEngineering #LearningEveryday #CleanCode
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 37/100 ✅ Binary Tree Postorder Traversal Today I solved the Binary Tree Postorder Traversal problem using a simple recursive approach in Java. In postorder traversal, we visit nodes in the order Left → Right → Root. This helps in many real-world tree-based algorithms like expression tree evaluations or file system traversal. 💡 Approach: I used recursion — first visiting the left child, then the right child, and finally adding the node’s value to the result list. It’s clean, elegant, and easy to understand! ✅ Key Learning: Understanding traversal patterns (Preorder, Inorder, Postorder) is essential for mastering tree-based problems. Each pattern teaches how to process data at different stages of recursion. #LeetCode #Java #CodingJourney #DSA #BinaryTree #Recursion #PostorderTraversal #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 LeetCode Day--- 4 | “Median of Two Sorted Arrays” (Hard, Java) Today’s challenge was one of those that really test your logic, patience, and understanding of binary search. This problem wasn’t about just merging two sorted arrays — it was about thinking smarter 🧠. Instead of brute-forcing through both arrays (O(m+n)), I implemented a binary partition approach to achieve O(log(min(m, n))) efficiency 💡 What I learned today: Always choose the smaller array for binary search — it makes the partition logic simpler. Handle boundaries carefully with Integer.MIN_VALUE and Integer.MAX_VALUE. The goal is to find the perfect partition where: Left half ≤ Right half Elements are balanced across both arrays Once that’s done → median can be easily calculated! ✅ Result: Accepted | Runtime: 0 ms 🚀 Hard problem turned into a logic puzzle that was actually fun to solve! 🧩 Concepts Strengthened: Binary Search Partitioning Logic Edge Case Handling Mathematical Thinking #LeetCode #Day4 #Java #BinarySearch #ProblemSolving #CodingChallenge #DataStructures #Algorithms #CodeEveryday #DeveloperJourney #TechLearning #LeetCodeHard #CodingCommunity
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