Solved the classic Valid Parentheses problem using a stack-based approach in JavaScript. Key idea: Use a stack to track opening brackets and a hash map to validate closing pairs efficiently in O(1). Approach: Push opening brackets (, {, [ onto the stack On encountering a closing bracket, check: If stack is empty → invalid If top of stack doesn’t match → invalid At the end, stack must be empty for a valid string Optimized with: Single pass traversal → O(n) time complexity Stack space → O(n) worst case This problem reinforces a fundamental pattern: Stack + Mapping = Efficient bracket validation #JavaScript #DataStructures #Algorithms #Stack #CodingInterview #LeetCode
Sayan Duary’s Post
More Relevant Posts
-
🔁 Understanding the forEach() loop in JavaScript The forEach() method is a simple way to iterate over arrays and perform an action for each element. 👉 Syntax: array.forEach((item, index) => { // logic here }); 👉 Example: const numbers = [1, 2, 3, 4]; numbers.forEach((num, index) => { console.log(`Index: ${index}, Value: ${num}`); }); 💡 Key Points: ✔️ Executes a function for each array element ✔️ Does not return a new array ✔️ Cannot break or use return to stop the loop If you need a return value, consider using map() instead. Small concepts like this build a strong JavaScript foundation 🚀 #JavaScript #WebDevelopment #Frontend #Coding #LearnToCode
To view or add a comment, sign in
-
You don’t need 5 lines to extract values from an object. If you’re still doing that, you’re writing bad JavaScript. There’s a cleaner way: 👉 Destructuring Less repetition. Cleaner code. Easier to read. Once you start using it, going back feels wrong. 🔗 Read here: https://lnkd.in/dw9j7a6t What should I cover next — Spread/Rest or Promises? #javascript #webdevelopment #coding
To view or add a comment, sign in
-
-
If you're only using Arrays and Objects in JavaScript, you're limiting yourself. Map and Set exist for a reason — and they solve problems cleaner. → Need unique values? Set does it instantly → Need proper key-value storage? Map beats Object Less workaround. More clarity. Wrote a quick breakdown with examples. Read here: 🔗 https://lnkd.in/drqhd7Vg #JavaScript #WebDevelopment #Coding
To view or add a comment, sign in
-
-
🚀 From Arrays to Efficiency: Mastering Set in JavaScript Today I solved the “Unique Rows in Boolean Matrix” problem using one simple yet powerful concept — Set. At first glance, the problem looks like a typical nested loop challenge. But instead of going brute force, I leveraged Set to achieve a clean and optimal solution. 💡 Key Idea: Convert each row into a string and store it in a Set to automatically handle duplicates. ✨ Why this is powerful: Eliminates duplicates in O(1) lookup time Avoids unnecessary nested loops Keeps the solution clean and readable 📊 Complexity: Time: O(n × m) Space: O(n × m) 🔥 Takeaway: Sometimes, the difference between an average solution and an optimal one is just knowing the right data structure. Today it was Set. Tomorrow, it could be something else. 💬 Curious: Where else have you used Set to simplify a problem? #JavaScript #DSA #CodingInterview #WebDevelopment #ProblemSolving #100DaysOfCode
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
-
-
🚀 Dynamic Currying in JavaScript — Why it actually matters At first, currying feels like a trick: sum(1)(2)(3) But the real power isn’t syntax — it’s reusability. 💡 The idea 👉 Fix some arguments now 👉 Reuse the function later 🔧 Example const filter = fn => arr => arr.filter(fn); const filterEven = filter(x => x % 2 === 0); filterEven([1,2,3,4]); // [2,4] Instead of repeating logic everywhere, you create reusable building blocks. ⚡ Real-world uses API helpers → request(baseUrl)(endpoint) Logging → logger("ERROR")(msg) Event handlers → handleClick(id)(event) Validation → minLength(8)(value) 🧠 Key takeaway Currying isn’t about fancy functions. It’s about writing code that is: ✔ Reusable ✔ Composable ✔ Cleaner Libraries like Lodash and Ramda use this pattern heavily. Once this clicks, your approach to writing functions changes completely. #JavaScript #WebDevelopment #FunctionalProgramming #Currying #CleanCode #Frontend #Coding #100DaysOfCode #DeveloperJourney #TechCommunity
To view or add a comment, sign in
-
-
JavaScript Under the Hood For the past two weeks, I have been delving into the internal workings of JavaScript. Here are the topics I have covered in detail: * Window object * Memory execution phase * Code execution phase * Global Execution Context * Function Execution Context * Closures and lexical scopes * Binding the 'this' keyword * Reference types * Heap and stack * DOM: * Repaint * Reflow * C++ DOM nodes * Event capturing and bubbling * Render tree Asynchronous JavaScript: * Event loop * Call stack * Promises * Microtasks * Macrotasks * Callback hell Objects: * Prototypes * The 'this' keyword * Shallow copy * Deep copy And many more topics. you can watch Lydia Hallie Youtube channel to learn some of the concepts . youtube channel ** https://lnkd.in/dFPqHBUv
To view or add a comment, sign in
-
-
🚀 Understanding Template Literals in JavaScript 📖 Read full guide: https://lnkd.in/ghJ6jZRm While working with JavaScript, I explored how Template Literals simplify string handling and improve code readability. 🔍 Old way (messy): "Hello " + name + "!" ✨ New way (clean): Hello ${name}! 💡 Key Benefits: ✔ Easy variable embedding ✔ Multi-line strings ✔ Cleaner, more readable code Small feature, but a big impact in modern JavaScript 🚀 #JavaScript #WebDevelopment #Coding #FrontendDevelopment #LearningJourney #CleanCode
To view or add a comment, sign in
-
-
hi connections Day 22 of 30: Extending the Prototype with LeetCode 2619 🚀 Today’s challenge, Array Prototype Last, dives into one of JavaScript’s most powerful features: Prototypal Inheritance. Instead of writing a standard function, the task was to enhance the global Array object so that every array can call .last() to retrieve its final element. The Logic By adding a method to Array.prototype, we make it available to every array instance. Inside the function, the this keyword refers to the array itself, allowing us to access its length and indices. Key Takeaways: The "this" Context: Understanding how this refers to the calling object is crucial for building custom utilities. Edge Case Handling: In this problem, returning -1 for empty arrays is a specific requirement that differs from the usual undefined. Efficiency: Accessing an element by index is O(1), making this a lightning-fast operation regardless of array size. Customizing prototypes is a common practice in library development, and mastering it helps in writing cleaner, more intuitive code for complex applications. One more day down, more logic mastered! 💻✨ #JavaScript #LeetCode
To view or add a comment, sign in
-
-
new blog. 📝 Destructuring in JavaScript cleaner code. less repetition. more readable. destructuring is one of those features you don't know you needed until you use it once then you can't stop. link: https://lnkd.in/gNgvuG-4 Hitesh Choudhary Piyush Garg Akash Kadlag Jay Kadlag
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