Postorder Traversal: Two-Stack Approach 👉 Day 67 / Day 93 👈 16 🔥 This method ensures nodes are processed in the correct Left → Right → Root order while keeping the logic clean and iterative. Initialization s1 → used to process nodes (like a working stack). s2 → used to store nodes in reverse order. res → final result array. #JavaScript #Coding #DataStructures #Algorithms #BinaryTree #PostorderTraversal #TechLearning #CodeSnippet #ProgrammingTips #DeveloperCommunity
Postorder Traversal with Two-Stack Approach
More Relevant Posts
-
📌 #45 DailyLeetCodeDose Today's problem: 141. Linked List Cycle – 🟢 Easy There are two ways to solve such tasks 1. Mark visited nodes, ex. by putting them into hash map 2. More clever way to avoid using extra space – 🦍 Floyd’s Cycle Finding Algorithm The main idea of this algorithm is to use 2 pointers at the same time: slow and fast. Slow goes by 1 step, fast by 2 on each cycle iteration. If two pointers on the same list node, we found a cycle! If you want to read more about it, here is the link: https://lnkd.in/ex25Eyvc Link to the leetcode promlem: https://lnkd.in/eM8KTdy2 #DailyLeetCodeDose #LeetCode #JavaScript #Algorithms #ProblemSolving #Coding
To view or add a comment, sign in
-
-
Minimizing Maximum Pair Sum in Arrays 👉 Day 75 / Day 93 👈 23🔥 The idea: Sort the array Pair smallest with largest, second smallest with second largest, and so on Track the maximum sum among all pairs Example: nums = [3, 5, 2, 3] Sorted: [2, 3, 3, 5] Pairs: (2, 5) = 7, (3, 3) = 6 Maximum pair sum = 7 👉 This is the minimized maximum pair sum. #Coding #Algorithms #DataStructures #JavaScript #TypeScript #CleanCode #ProblemSolving #LeetCode #InterviewPrep
To view or add a comment, sign in
-
-
Day 184: Moving Nodes and Counting Words I am now on Day 184! Today, I practiced more Linked List logic and started working with Strings. Here is what I did today in very simple steps: 1. Rotate List (LeetCode 61) 🔄 I learned how to take the end of a list and move it to the front. How? First, I find the length of the list. Then, I find the right place to "cut" the list and connect the end back to the start. 2. Swap Nodes in Pairs (LeetCode 24) 🤝 I learned how to swap every two nodes. For example, 1 -> 2 -> 3 -> 4 becomes 2 -> 1 -> 4 -> 3. The Trick: I used a "Sentinel" node to keep track of the head. I also tried a Recursive version, which made the code very short and clean! 3. Length of Last Word (LeetCode 58) 📏 I moved to Strings! I had to find the length of the very last word in a sentence. Manual Way: Instead of using easy shortcuts, I started from the end of the string, skipped the empty spaces, and counted the letters until I hit another space. It is a great way to practice loops. My takeaway: Whether it is cutting a list or counting letters backward, logic is all about finding the right starting point! #JavaScript #Coding #Programming #WebDevelopment #DataStructures #Algorithms #SoftwareEngineer #Logic #SimpleLearning #StringManipulation #LinkedList #TechCommunity #DailyCoding #ProblemSolving #CareerGrowth #CodeNewbie
To view or add a comment, sign in
-
🚨 "Cannot read properties of undefined" in production. 🚨 Have you ever been frustrated to fix this error in minified & obfuscated code? Unfortunately, you can’t enable source maps in production — but don’t worry, I’ve got you covered. In my latest article, I walk you through step-by-step ways to debug this error, even in fully minified code. All you need is the stack trace. And trust me, it isn't just about adding a "?" everywhere. 👀 The article covers: ✅ Decoding stack traces and reverse engineering the execution path back to the root cause. ✅ Identifying the internal symbols and what they represent. ✅ Implementation of defensive coding patterns that actually work to avoid such issues in production. #webdevelopment #angular #javascript #typescript #debugging #cleancode #coding
To view or add a comment, sign in
-
🚀 LeetCode: Valid Palindrome The goal is to determine if a string is a palindrome, considering only alphanumeric characters and ignoring cases. 🛠️ My Approach 1. Preprocessing: Converted the entire string to lowercase to ensure the check is case-insensitive. 🔡 2. Filtering: Used a regex-based loop (/[a-z0-9]/) to strip away non-alphanumeric characters, creating a clean string of only valid characters. 🧹 3. Two-Pointer Optimization: Instead of reversing the string (which takes extra time and memory), I used two pointers starting at opposite ends. 📍 One pointer moves from the start (i), and the other from the end (j). ❌ If the characters at these positions ever mismatch, we return false immediately. 📊 Efficiency Analysis ⏱️ Time Complexity: $O(n) 💾 Space Complexity: $O(n) #LeetCode #JavaScript #CodingLife #Algorithms #WebDevelopment #ProblemSolving #SoftwareEngineering #TechCommunity
To view or add a comment, sign in
-
-
Recursion is just a conversation with the future. I used to think of recursion as a "fancier loop." I was wrong. I realized that when you call a function twice inside itself, you aren't just repeating code—you are creating a "Branching Factor." Each call pauses the parent and creates a new instance. If you do this in a loop, your execution stack explodes exponentially! While a loop moves horizontally through an array, recursion moves vertically. Every time sum calls itself, the computer "pauses" the current calculation and opens a new layer on the Call Stack. The logic breakdown: We ask for the value at index 0. We wait for the value of index 1... which waits for index 2... Once we hit the Base Case (the end of the array), the values start "bubbling up" back to the start. Key Lesson: Understanding the Call Stack is the difference between a working app and a "Stack Overflow." #JavaScript #Coding #WebDevelopment #DataStructures
To view or add a comment, sign in
-
-
📌 LeetCode | Binary Search & Insert Another Binary Search problem — Search a target in a sorted array. If the target doesn’t exist, return the index where it should be inserted. 🔹 Approach: Modified Binary Search 🔹 Time Complexity: O(log n) 🔹 Space Complexity: O(1) 🔹 Result: Accepted ✅ (All test cases passed) Key learning here: Binary Search isn’t just about finding elements — it’s also about identifying the correct position. Small twist, same core logic. These variations really sharpen problem-solving instincts. #DSA #BinarySearch #LeetCode #Coding #ProblemSolving #JavaScript #DailyProgress
To view or add a comment, sign in
-
-
🚀 Understanding Recursive Traversal: Why Is It Synchronous and Blocking? 🤔 When we talk about recursive traversal—whether it's navigating trees, graphs, or other data structures—it's important to recognize why this process is inherently synchronous and blocking. 🔍 Here’s the gist: Recursive calls happen on a single call stack, and each call waits for its deeper calls to return before continuing. This linear, step-by-step process ensures order but also means no parallel execution. As a result, recursive traversal blocks the thread until all sub-calls complete, making it inherently synchronous. This is just how recursion operates by nature—it’s a control flow mechanism, not a concurrency technique. React’s reconciliation algorithm in earlier versions traversed its virtual DOM tree synchronously using recursive, call stack–based traversal — meaning the whole render and commit process blocked the main thread until done. This recursive depth-first traversal blocks the browser’s main thread, causing UI jank on large trees. There was no built-in mechanism to pause or yield this traversal, making it blocking and synchronous by design. Have you experienced blocking recursive code before? Share your stories below! 💬 #ReactJS #JavaScript #FrontendDevelopment #SoftwareEngineering #RecursiveAlgorithms #CallStack #ReactFiber #AsyncProgramming #WebPerformance #DeveloperExperience #CodeOptimization #TechInsights #Programming #OpenSource
To view or add a comment, sign in
-
Next mission: learning Rust by refactoring a real compiler. Over the past months I’ve been building Zenith, a compiler-first UI framework focused on compile-time guarantees, zero runtime abstraction, and predictable behavior. Along the way, I hit a familiar ceiling: JavaScript is great for orchestration but once you start enforcing invariants, modeling IR, and guaranteeing correctness, it stops being the right authority. So the next step is clear. I’m beginning a deliberate, incremental refactor of the Zenith compiler into Rust not as a rewrite for speed, but as a way to: • Learn Rust properly (ownership, modeling, invariants, boundaries) • Move semantic authority out of JS and into a stricter system • Design a compiler that cannot “accidentally” work The plan is slow and boring on purpose: • Establish Rust as the semantic core • Keep JS as a thin orchestration layer • Verify correctness at every phase before moving on No hype. No rewrite frenzy. Just learning a powerful language by applying it to a real system with real constraints. If you’ve learned Rust through a non-trivial projector have opinions on compiler boundaries. I’d love to hear them.
To view or add a comment, sign in
-
🧩 LeetCode Lesson | 3813. Vowel–Consonant Score At first glance, this problem felt too easy — count vowels, count consonants, return the score. That assumption turned out to be the real trap. What actually mattered here were the edge cases, not the logic itself. 🧠 Questions that forced careful thinking: • Should numbers be counted? • What about symbols? • What about space? • What if there are no consonants at all? Ignoring these details leads to wrong answers — even with “correct” logic. ⚙️ Approach • Iterate through each character • Count vowels explicitly • Count consonants using a regex check ([a-z]) • Ignore everything else • Handle division safely when consonants = 0 ⏱️ Complexity Time Complexity: O(n) Space Complexity: O(1) 📌 Key Takeaway Easy-looking problems often fail people not because of logic, but because of assumptions. #LeetCode #ProblemSolving #DSA #JavaScript #CodingJourney #LearnInPublic #EdgeCases #Consistency
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