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
Solved Binary Tree Postorder Traversal in Java using recursion
More Relevant Posts
-
🚀 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
-
-
🚀 Topological Sort | DFS Approach | Java Today I learned about Topological Sorting using Depth First Search (DFS) — a fundamental algorithm for Directed Acyclic Graphs (DAGs). 🔹 Concept: Topological sorting gives a linear ordering of vertices such that for every directed edge u → v, vertex u comes before v in the ordering. 🔹 Real-world uses: Course scheduling (prerequisites) Task dependency resolution Build order in compilers ⏱ Time Complexity: O(V + E) — each vertex and edge is processed once during DFS. 💾 Space Complexity: O(V) — for recursion stack, visited array, and stack to store results. 🏷️ Hashtags: #TopologicalSort #DFS #GraphAlgorithms #Java #DataStructures #Algorithms #CodingJourney #ProblemSolving #ComputerScience #LearningDSA
To view or add a comment, sign in
-
💻 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
To view or add a comment, sign in
-
-
🔥 #100DaysOfDSA — Day 29/100 Topic: Binary Search in Java ⚡ 💡 What I Did Today: Today, I implemented one of the most powerful and efficient searching algorithms — Binary Search 🔍 Instead of checking every element one by one like Linear Search, Binary Search smartly divides the array in half each time — reducing the time complexity drastically! 🧠 Logic Used: Works only on sorted arrays ✅ Find the mid index: mid = (start + end) / 2 If key == numbers[mid] → found the element 🎯 If key > numbers[mid] → search in right half Else → search in left half Continue until the element is found or the range is empty 📊 Example: Input → {4, 5, 6, 10, 18, 61, 122} Key → 61 ✅ Output → index for key is: 5 ⚙️ Time Complexity: O(log n) — super fast compared to O(n) of Linear Search 💨 ✨ Takeaway: Binary Search is a fundamental algorithm that teaches the power of divide and conquer. Mastering this concept builds the foundation for more advanced topics like search trees, sorting, and algorithm optimization 🚀 #100DaysOfCode #Day29 #Java #DSA #BinarySearch #ProblemSolving #CodingJourney #LearnInPublic #DeveloperLife #CodeNewbie
To view or add a comment, sign in
-
-
💻 DSA – Day 13 : Strings & StringBuilder Today I explored Strings in Java, a core concept used in almost every application — from input handling to algorithms, data processing, and problem-solving. Strings look simple, but there's a lot happening under the hood. 🌈 What I learned today 🔹 ❓ What are Strings? A sequence of characters stored as an object in Java. Strings are immutable, which means once created, they cannot be changed. 🔹 ⌨️ Input & Output Took string inputs using Scanner and printed them with basic operations. 🔹 📏 String Length Used .length() to find the number of characters. 🔹 ➕ String Concatenation Joined strings using +, concat(), and StringBuilder. 🔹 🔡 charAt() Method Accessed characters using index values. 🔹 🔄 Check if a String is Palindrome Compared characters from both ends to verify if the string reads the same backwards. 🔹 🧭 Shortest Path Problem Calculated the shortest path (N/E/W/S directions) using coordinate logic. 🔹 ⚖️ String compare() Compared strings lexicographically using .compareTo(). 🔹 ✂️ substring() Function Extracted specific parts of the string. 🔹 🏆 Print Largest String Compared strings alphabetically to find the largest one. 🔹 🔒 Why Strings Are Immutable? Because they are stored in the String Pool and designed for security, caching, and thread-safety. 🧵 StringBuilder – Faster & Mutable 🔹 Unlike Strings, StringBuilder is mutable 🔹 Perfect for modifying strings repeatedly (loops, concatenation, dynamic strings) ✨ Extra Concepts Learned 🔹 🔤 Convert Letters to Uppercase Converted the first letter of each word to uppercase (title case-style logic). 🔹 📦 String Compression Implemented character frequency compression like: aaabbccc → a3b2c3 🚀 Loving the learning curve Strings are everywhere — mastering them builds a strong foundation for upcoming DSA topics. #DSA #Strings #Java #StringBuilder #CodingJourney #100DaysOfCode #LearningInPublic #ProblemSolving #Day13
To view or add a comment, sign in
-
🚀 Day 35 of 100 Days of LeetCode 📘 Problem: Binary Tree Inorder Traversal 💻 Language: Java ✅ Status: Accepted — Runtime ⚡ 1 ms Today’s focus was on mastering tree traversal, one of the most essential techniques in data structures 🌳 The goal was simple — visit nodes in order (Left → Root → Right), but the recursive logic behind it reinforced clarity and structured thinking. ✨ Key Learnings: Recursive approach simplifies traversal logic 🧠 Base cases are the backbone of recursion Understanding tree patterns helps in mastering complex problems like BSTs and DFS 💬 “A binary tree teaches one thing — structure leads to clarity.” #Day35 #100DaysOfCode #LeetCode #Java #BinaryTree #Recursion #ProblemSolving #DSA #CodingJourney #SoftwareDevelopment #KeepLearning
To view or add a comment, sign in
-
-
🔢 Today I worked on a classic matrix problem in Java — Diagonal Sum. The goal was simple: Calculate the sum of both the primary and secondary diagonals of a square matrix. Initially, I used a nested loop approach with O(n²) complexity. But then I optimized it to a clean O(n) solution by directly accessing diagonal indexes. While optimizing, I made an interesting mistake: ❌ I wrote if (i != matrix[i][matrix.length - 1 - i]) Here I accidentally compared an index with an element value. ✔ Correct approach: if (i != matrix.length - 1 - i) This ensures the center element in odd-sized matrices isn’t counted twice. 🧠 Key Learning: Indexes and values may look similar, but mixing them can break logic silently. Optimization is not just about speed — it’s about accuracy. #Java #leetcode #Coding #DSA #ProblemSolving #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
-
✅ Learning Update: Today, I implemented Topological Sort using Kahn’s Algorithm (BFS approach) in Java. 🔹 What it does: Topological Sort helps in ordering the vertices of a Directed Acyclic Graph (DAG) such that for every directed edge u → v, vertex u appears before v in the ordering. It’s widely used in task scheduling, course prerequisite ordering, and build dependency resolution. ⏱ Time Complexity: O(V + E) 📦 Space Complexity: O(V) 💡 Key Takeaway: Kahn’s Algorithm provides a simple and efficient BFS-based way to get a valid topological order — especially useful when you want to detect cycles or manage dependencies efficiently. #Learning #DataStructures #Algorithms #GraphTheory #TopologicalSort #KahnsAlgorithm #JavaProgramming #CodingJourney #DSA #ProblemSolving #TechLearning #100DaysOfCode
To view or add a comment, sign in
-
📌 Day 12/100 - Concatenation of Array (LeetCode 1929) 🔹 Problem: Given an integer array nums, create a new array ans such that: ans[i] = nums[i] ans[i + n] = nums[i] where n is the length of nums. In short, we need to concatenate the array with itself to form a new array of size 2n. 🔹 Approach: First, determine the length n of the array. Create a new array newArray of size 2n. Loop through nums once: Assign each element twice — once at position i and once at position i + n. Finally, return the concatenated array. 🔹 Key Learning: Reinforced the concept of array indexing and iteration. Practiced efficient array manipulation in Java. Sometimes, the simplest logic is the cleanest — clarity beats complexity! 💡 Every solved problem adds a layer of confidence and consistency 💪 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #LearnByDoing
To view or add a comment, sign in
-
-
Day 39 — Ones and Zeroes (0–1 Knapsack Variation) Problem: 474. Ones and Zeroes Difficulty: Medium Language: Java Status: Solved Problem Summary: Given an array of binary strings strs and two integers m and n, find the maximum subset size such that the total number of '0's ≤ m and total '1's ≤ n. Key Concept: This is a 2D 0–1 Knapsack problem, where: Each string represents an item with two “weights”: count of '0's and '1's. We must maximize the number of strings (the “value”) within the constraints of available m and n. Algorithm Steps: Count zeros and ones for each string. Iterate backwards (to avoid overwriting previous states). Update dp[i][j] = max(dp[i][j], dp[i - zeros][j - ones] + 1) for all valid i, j. Time Complexity: O(len(strs) * m * n) Space Complexity: O(m * n) Learning Takeaway: This problem strengthens understanding of multidimensional dynamic programming. The backward iteration pattern is crucial in 0–1 Knapsack-style DP to prevent reuse of the same item. #Day39 #100DaysOfCode #LeetCode #DynamicProgramming #Knapsack #DP #Java #Algorithms #CodingChallenge #ProblemSolving #DSA
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