✅ Solved LeetCode: Binary Tree Postorder Traversal (145) Implemented a recursive Postorder Traversal in JavaScript, following the sequence: Left → Right → Root. The solution uses a helper function traversal(curr) that: - First explores the left subtree, - Then explores the right subtree, - And finally processes the current node by pushing its value to the result array. This traversal is especially useful in scenarios like deleting a tree, evaluating expression trees, or bottom-up processing of nodes. ⏱ Time Complexity: O(n) — every node is visited once 🧠 Space Complexity: O(h) — recursion stack, where h is the height of the tree A key traversal technique every DSA learner should master! 🌳🚀
Binary Tree Postorder Traversal Solution in JavaScript
More Relevant Posts
-
🚀 Day 8 :-JavaScript & DSA Fundamentals 🌳 Understanding the Prototype Chain Root level: Object.prototype Then: Array.prototype, Function.prototype, String.prototype Learning how inheritance works using: Object.create(obj1) This helped me truly understand prototype-based inheritance in JavaScript. ⚙️ Mastering Functions in Different Ways Function declarations Function expressions Arrow functions Parameters vs Arguments Spread vs Rest operators Understanding how this behaves differently in arrow functions was a big insight. 🔁 Control Flow & Logic Building if / else / nested if for / while / do while switch statements Nested loops Variable scope (global, local, block) Why avoiding var prevents scope-related bugs 🧠 Deep DSA Practice I spent an entire day solving: Search in Rotated Sorted Array in complete day i create logic only above problem but i learn a lot from this problem to understanding about binary search in depth #JavaScript #DSA #WebDevelopment #LearningInPublic #ProblemSolving #FrontendDeveloper
To view or add a comment, sign in
-
🚀 LeetCode Problem Solved – Sort Characters by Frequency Today I solved the “Sort Characters By Frequency” problem on LeetCode. 🔎 Problem Statement: Given a string, sort its characters in decreasing order based on their frequency. 🧠 Key Learning: Instead of directly sorting the string (which isn’t possible since strings are immutable in JavaScript), I: ✔ Counted the frequency of each character using an object ✔ Extracted keys using Object.keys() ✔ Sorted them based on frequency (descending order) ✔ Rebuilt the final string using nested loops 💡 Concepts Used: HashMap / Object for frequency counting Custom sorting with comparator function String building using loops Time Complexity optimization thinking ✨ Example: Input: "tree" Output: "eert" This problem strengthened my understanding of: Frequency-based sorting Custom comparator logic Clean DSA implementation in JavaScript Consistency in solving DSA problems daily 🚀 #LeetCode #DSA #JavaScript #ProblemSolving #CodingJourney #FrontendDeveloper #100DaysOfCode
To view or add a comment, sign in
-
-
✨ 𝗗𝗮𝘆 𝟱 𝗼𝗳 𝗠𝘆 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗝𝗼𝘂𝗿𝗻𝗲𝘆 🚀 Today I explored 𝗡𝘂𝗺𝗯𝗲𝗿𝘀 𝗮𝗻𝗱 𝘁𝗵𝗲 𝗠𝗮𝘁𝗵 𝗢𝗯𝗷𝗲𝗰𝘁 in JavaScript, and learned some interesting behind-the-scenes details: • 𝗡𝘂𝗺𝗯𝗲𝗿 – integers, floats, NaN, Infinity • 𝗠𝗮𝘁𝗵 𝗢𝗯𝗷𝗲𝗰𝘁 – handy methods like Math.round(), Math.floor(), Math.ceil(), Math.random(), Math.max(), Math.min() • 𝗠𝗮𝘁𝗵.𝗿𝗮𝗻𝗱𝗼𝗺() – generates pseudo-random numbers, which means it’s not truly random. It’s predictable if you know the algorithm and therefore shouldn’t be used for OTPs or secure codes. It’s fascinating to see how much thought goes into even simple math operations in JavaScript. Step by step, my fundamentals are getting stronger! 💪 #JavaScript #100DaysOfCode #WebDevelopment #LearningJourney #FrontendDevelopment #CodingTips
To view or add a comment, sign in
-
-
✨ 𝗗𝗮𝘆 𝟰 𝗼𝗳 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 🚀 Today I learned about 𝗖𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻𝗮𝗹𝘀, 𝗟𝗼𝗼𝗽𝘀, 𝗮𝗻𝗱 𝗢𝗽𝗲𝗿𝗮𝘁𝗼𝗿𝘀 — the core logic that makes programs think and repeat tasks. But what really surprised me was what happens behind the scenes when we compare values. I discovered why floating-point calculations can be unpredictable in JavaScript. 𝗙𝗼𝗿 𝗲𝘅𝗮𝗺𝗽𝗹𝗲: 𝟬.𝟭 + 𝟬.𝟮 !== 𝟬.𝟯 This happens because JavaScript uses binary floating-point representation (IEEE 754), and some decimal numbers can’t be represented exactly in binary. So tiny precision errors appear. It’s fascinating to see that even simple math has deep computer science concepts behind it. Every day I realize: writing code is one thing, understanding it deeply is another. 💪 #JavaScript #100DaysOfCode #WebDevelopment #LearningJourney #ComputerScience
To view or add a comment, sign in
-
-
Continuing my journey into JavaScript, I’ve just published a new blog post! This time, I’m breaking down JavaScript Operators—the fundamental building blocks that allow us to manipulate data and build logic in our code. In this guide, I cover: ✅ Arithmetic Operators (+, -, *, /, %) – The math behind the logic. ✅ Comparison Operators (==, ===, !=, >, <) – Understanding how to evaluate conditions . ✅ Strict Equality (===) – Why type checking matters! ✅ Logical & Assignment Operators (&&, ||, !, =, +=) – Flow control and data handling. I’ve included plenty of practical examples to make these concepts stick for good. A big shoutout once again to Hitesh Choudhary sir for the incredible guidance in making these basics so clear and easy to understand. Check out the full guide here: https://lnkd.in/e7s4tANn Akash Kadlag | Jay Kadlag | #JavaScript #CodingBasics #WebDevelopment #Programming #Hashnode #TechCommunity #LearnToCode #chaiaurcode
To view or add a comment, sign in
-
-
React Learning Series | Contd... #Day10: Understanding State Immutability and How Immer helps. In JavaScript: 👉 Immutable → strings, numbers, booleans, primitives 👉 Mutable → objects (arrays and functions are objects too 😉) ❗ But In React… 🔴 When objects are stored in state, you must treat them as immutable. ❌ You can't : state →user →name: 'Arpita' ✅ setState({ ...state, someProp: newValue }); 🚫 The Problem 🔴 When state becomes deeply nested: state → user → profile → address → city ❗ Updating it immutably becomes messy: ❌ Multiple spreads ❌ Hard to read ❌ Easy to make mistakes ✴️ useImmer helps us here updateUser(draft => { draft → user → profile → address → city="Bangalore"; }); 👉 Looks mutable, but internally: ✅ It creates a new immutable copy ✅ Tracks changes efficiently 🔥 Why It’s Useful 👉 Cleaner code 👉 Safer deep updates 👉 Reduces boilerplate 👉 Great for complex state shapes #React #Immer #StateManagement #FrontendDevelopment
To view or add a comment, sign in
-
🚀 Cracked a tricky DSA concept today — Search in Rotated Sorted Array (with duplicates) At first glance the array looks unsorted… But actually it’s two sorted arrays joined together 🔍 Example: [2,5,6,0,0,1,2] The challenge ❓ Find a target efficiently (not O(n)) → Use Modified Binary Search (O(log n)) 💡 Key Learning: 1️⃣ One half of the array is always sorted 2️⃣ Check if target lies in the sorted half 3️⃣ If duplicates confuse the search → shrink the window (left++, right--) Core logic: • All equal → ignore edges • Left sorted → search there • Else → search right side 📈 What I learned: Understanding the logic is more important than memorizing code. Today I didn’t just solve a problem — I understood how to think like an algorithm. #DSA #BinarySearch #JavaScript #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
Headline: 🧠 Thinking Mathematically: Finding the GCD of Strings The Content: Continuing my JavaScript challenge on LeetCode! Today I tackled the "Greatest Common Divisor of Strings" problem. This one is fascinating because it blends string logic with classic number theory. The Challenge: Given two strings, find the largest string x such that x divides both str1 and str2. My Approach: The Concatenation Test: A brilliant trick for this problem is checking if str1 + str2 === str2 + str1. If they don't match, a common divisor string literally cannot exist. The GCD Logic: If they pass the test, the length of the greatest common divisor string must be the GCD of the lengths of the two strings. The Solution: I implemented a recursive helper function using the Euclidean Algorithm to find the gcdLength, then simply sliced the prefix! Technical Efficiency: Time Complexity: $O(n + m)$ due to string concatenation and comparison. Space Complexity: $O(n + m)$ to store the concatenated strings. Key Reflection: It’s amazing how concepts from basic math (like GCD) find their way into modern software engineering problems. It’s all about finding the pattern before writing the first line of code. Onward to the next challenge! 📈 #LeetCode #JavaScript #CodingChallenge #ProblemSolving #SoftwareEngineering #Algorithms #MathInCode #WebDevelopment
To view or add a comment, sign in
-
-
Sometimes the best learning projects start as “just for fun.” I built a VSCode extension for fun that counts every React component inside a folder and its subfolders. But the interesting part wasn’t the counting. I had to figure out: • How to reliably detect React components • How to parse large JS/TS files safely • How to traverse an entire project efficiently That led me into studying Abstract Syntax Trees and building the extension using Babel for accurate code analysis instead of fragile string matching. What started as curiosity turned into a full static analysis tool that scans entire React codebases and provides insights into component distribution and hook usage. Instead of relying on regex, I parsed files into Abstract Syntax Trees using Babel to accurately detect function and class components across .js, .jsx, .ts, and .tsx files. To traverse large projects, I implemented a depth-first search and used a hash map for efficient file tracking and caching. The extension ended up being used by hundreds of developers. #vscode #React
To view or add a comment, sign in
-
Day 2/30 — DSA Insight 🌙 Understanding time complexity is key to writing efficient code. Example in JavaScript: O(n) — Linear (scales well): for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } O(n²) — Quadratic (slows down with large input): for (let i = 0; i < arr.length; i++) { for (let j = 0; j < arr.length; j++) { console.log(arr[i], arr[j]); } } ✅ Lesson: Always reason about efficiency before coding. Linear is fast, quadratic can kill performance. #DSA #JavaScript #TimeComplexity #BuildInPublic #CodingTips
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