Easter tree? 🌳 🪺 It’s very similar to the LeetCode 103 problem (Binary Tree Zigzag Level Order Traversal), but this time we don’t need to return an array of values. Instead, we need to mutate the tree and apply the changes directly to the nodes. So we traverse the tree level by level, collect all the nodes on each level, and then reverse the values on every odd level. We also have to remember that we don’t want to change the order of the nodes themselves, only their values. That’s why the built-in reverse() method isn’t enough here. We need a custom algorithm that swaps the values directly (Two pointers). #javascript #interview #node
Mariusz Najwer’s Post
More Relevant Posts
-
🚀 JavaScript Interview Question You Should Know ❓ What will be the output? console.log(a); var a = 10; console.log(b); let b = 20; 💡 Output: undefined ReferenceError: Cannot access 'b' before initialization 🧠 Explanation: 👉 var a Variables declared with var are hoisted They are initialized with undefined So internally: var a; console.log(a); // undefined a = 10; 👉 let b let is also hoisted BUT… It stays in the Temporal Dead Zone (TDZ) until initialized So accessing it before initialization: console.log(b); // ❌ ReferenceError let b = 20; 🎯 Key Takeaways: ✔ var → hoisted + initialized as undefined ✔ let/const → hoisted but NOT initialized (TDZ) #JavaScript #WebDevelopment #Frontend #CodingInterview #LearnToCode
To view or add a comment, sign in
-
-
Just published a new blog on Array Flattening in JavaScript 🚀 At first glance, it feels like a small concept… but once you go deeper, it touches recursion, problem-solving, and even interview-level thinking. In this blog, I covered: • What nested arrays actually are (with clear visuals) • Step-by-step thinking behind flattening • Different approaches (flat(), recursion, reduce, iterative) • Common interview scenarios and edge cases If you're learning JavaScript or preparing for interviews, this will be useful 👇 https://lnkd.in/gQgjYv54 #JavaScript #WebDevelopment #FrontendDevelopment #Coding #LearnInPublic #100DaysOfCode #Programming #SoftwareDevelopment
To view or add a comment, sign in
-
Day 85 of #100DaysOfCode Today I learned the Sliding Window technique, a powerful pattern for solving subarray and substring problems. Covered: • Fixed window problems • Variable window problems • Optimizing time complexity • Real interview patterns This technique is widely used in coding. #DSA #CodingInterview #JavaScript #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 4/30 – JavaScript Challenge Solved: Counter II (LeetCode 2665) Today’s problem was all about understanding closures and how functions can maintain their own state in JavaScript. What I learned: 1.How closures help preserve variable values across function calls 2.Creating multiple operations (increment, decrement, reset) using a single function 3.Clean use of arrow functions for concise code Approach: I created a function that stores the initial value and returns an object with three methods: 1.increment() -> increases value 2.decrement() -> decreases value 3.reset() -> resets to initial value All of this works because of closure, where the inner functions still remember the variable n. Key Insight: Closures are powerful when you need to encapsulate data and control how it’s modified — a very common pattern in real-world JavaScript applications. Consistency is the real game here 🔥 Let’s keep building, one day at a time. #Day4 #30DaysOfCode #JavaScript #WebDevelopment #CodingChallenge #LeetCode #Closures #LearningJourney
To view or add a comment, sign in
-
-
🚀 Mastering the Sliding Window Pattern in JavaScript One of the most powerful techniques for solving array problems efficiently is the Sliding Window + Deque approach. Today, I implemented the classic “Maximum in Sliding Window” problem in O(n) time 👇 🔍 Problem: Given an array and a window size k, return the maximum value in each window as it slides from left to right. 💡 Key Insight: Instead of recomputing the max for each window (which is expensive), we maintain a Deque (double-ended queue) that: Stores indices (not values) Keeps elements in decreasing order Ensures the front always holds the max ⚡ Result: Efficient solution with linear time complexity — each element is processed once. 📚 I’m currently building a collection of algorithm patterns in JavaScript: 👉 https://lnkd.in/ej4fNeZs #JavaScript #Algorithms #DataStructures #CodingInterview #SoftwareEngineering #100DaysOfCode
To view or add a comment, sign in
-
-
#Hello #Connections 👋 #100DaysOfCodeChallenge | #Day52 🚀 Just Built a Random Password Generator 🔐 I recently created a Random Password Generator using HTML, CSS, and JavaScript. 💻 Features: Generate strong and secure passwords Includes uppercase, lowercase, numbers, and symbols Copy to clipboard functionality Clean and responsive UI ⚠️ Challenges I Faced: While building this project, I encountered some interesting issues that helped me improve my debugging skills 👇 Issue 1: Password not generating properly Solution: Fixed logic by properly using random character selection Issue 2: Copy button not working Solution: Used navigator.clipboard.writeText() correctly Issue 3: Weak password generation Solution: Ensured inclusion of all character types Issue 4: JavaScript not working Solution: Fixed script linking and DOM loading issues ✨ This project helped me strengthen my understanding of: JavaScript logic building DOM manipulation Event handling 🔗Github Link :https://lnkd.in/dAjqqBgK Code Of School || Ritendra Gour sir || Avinash Gour sir #JavaScript #WebDevelopment #100DaysOfCode #Frontend #CodingJourney
To view or add a comment, sign in
-
In my previous blog, I explored String Polyfills and common interview methods — understanding how JavaScript works behind the scenes. Today, I went deeper into another fundamental concept: 👉 The new Keyword in JavaScript At first glance, it looks simple. But internally, it performs multiple steps that directly impact how objects, prototypes, and this behave. In this blog, I covered: ✔️ What the new keyword actually does ✔️ Step-by-step object creation process ✔️ How prototype linking works ✔️ Relationship between constructor and instances ✔️ Common mistakes (like forgetting new) And most importantly 👇 ⚠️ Confusing parts developers often struggle with: Array() vs new Array() Object creation patterns Constructor return behavior If you’re preparing for interviews or want to strengthen your JavaScript fundamentals, this will clear a lot of hidden concepts. 🔗 Read the full blog here: https://lnkd.in/grUGpMqe Next up in the series: JavaScript Modules (import/export) 🚀 #javascript #webdevelopment #frontenddeveloper #programming #softwaredevelopment #coding #100daysofcode #learninpublic
To view or add a comment, sign in
-
-
🚀 JavaScript Array Methods You Should Know If you’re still looping through arrays manually, there’s an easier way 👇 These array methods can make your code cleaner, faster to read, and easier to maintain: ✅ filter() → Get matching items ✅ map() → Transform data ✅ find() → Get the first match ✅ some() → Check if at least one item matches ✅ every() → Check if all items match ✅ includes() → Check if a value exists ✅ findIndex() → Find the position of an item ✅ push() / pop() → Add or remove items 💡 Pro tip: In React, map() and filter() are used a lot for rendering lists and handling data properly. Mastering these methods can help you write better code and do better in interviews 💻✨ Which array method do you use most often? 🤔 #JavaScript #WebDevelopment #ReactJS #FrontendDevelopment #Programming #Coding #Developer #SoftwareDevelopment #LearnToCode #CodingTips
To view or add a comment, sign in
-
-
🚀 JavaScript Last-Minute Cheat Sheet — Perfect Before Interviews & Coding Rounds 🔥 Variables & Scope • "let" & "const" over "var" • Block scope matters • Avoid global variables ⚡ Functions • Arrow functions → shorter syntax • Default parameters save time • Closures = function + lexical scope 🧠 Async JavaScript • Callbacks → Promises → "async/await" • Use "try...catch" for error handling • "Promise.all()" for parallel execution 📦 Arrays & Objects • "map()", "filter()", "reduce()" = must know • Spread "..." & Destructuring simplify code • Optional chaining "?." prevents crashes 🎯 DOM & Events • "querySelector()" is your best friend • Event delegation improves performance • Debounce & throttle for optimization 💡 Pro Tip Understand concepts, not just syntax. Clean code + problem-solving mindset = real JavaScript mastery. Learn more From w3schools.com ✨ #JavaScript #WebDevelopment #FrontendDeveloper #CodingInterview #100DaysOfCode
To view or add a comment, sign in
-
🚨JavaScript Interview Question What will be the output? function greet(name) { if (name === undefined) { console.log("Hello, guest!"); } else { console.log("Hello, "+ name); } greet(); greet("Anas"); greet("Anas", "How are you?"); Looks simple... but there's a twist What will be the output? Why does the last call behave differently? Bonus: How does JavaScript handle extra arguments? #JavaScript #FrontendInterview #WebDevelopment #CodingInterview #ProductBasedCompany
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
The zigzag part trips people up because they confuse node order with value order. reverse() on the array breaks the structure. most solutions iterate twice per level—collect, then swap. single pass with two pointers from opposite ends cuts that in half