Just solved the Min Stack problem with an optimized O(1) approach for all operations. Key takeaway: Maintaining an auxiliary stack to track the minimum at each step ensures constant-time retrieval without additional traversal. Operations achieved: push → O(1) pop → O(1) top → O(1) getMin → O(1) This problem reinforces an important pattern: augmenting data structures to trade space for time efficiency. Always satisfying to see clean logic translate into solid performance. #DataStructures #JavaScript #ProblemSolving #LeetCode #Algorithms
Optimized Min Stack with O(1) Operations
More Relevant Posts
-
Sometimes the biggest bottleneck in your code isn't the algorithm itself, but how the language handles memory. 💻 Just crushed a complex query problem with a 100% runtime. To get the execution time this low (389ms), I had to step away from standard JavaScript practices and optimize for the machine: Instead of creating new arrays and triggering heavy GC pauses, I allocated a BigUint64Array exactly once and overwrote it. By combining this with Square Root Decomposition for modular arithmetic, the processing time plummeted. A great reminder that when dealing with large datasets, thinking about memory allocation and data types is just as important as the logic itself. #CodingJourney #JavaScript #DataEngineering #Optimization #LeetCode
To view or add a comment, sign in
-
-
Day 04 of Learning JavaScript Deep Today’s topic looked simple… but turned out to be powerful Traversing an Array - Visiting each element one by one. Example: let arr = [10, 20, 30, 40]; for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } 🧠 Key understanding: Arrays start at index 0 End at length - 1 One mistake can break logic 👇 for (let i = 0; i <= arr.length; i++) { console.log(arr[i]); // undefined at end ❌ } 💭 Simple thought: “Array is just data… Traversal is how you understand it.” Small concept… big impact 🔥 #Day04 #JavaScript #FrontendDevelopment #LearningDeep #Traversing #Arraybasics
To view or add a comment, sign in
-
🚀 DSA Day 17: From Theory to Code – Building the Foundation 🏗️ Today was a busy one, but I made sure to squeeze in some growth time. I focused on the "blueprint" of a Singly Linked List: ✅ The Node Factory: Created a constructor to give every piece of data its own value and a next pointer. ✅ The Structure: Initialized my MyLinkedList class with a head, tail, and a length tracker to keep things organized. It’s a simple start, but it’s the skeleton that makes everything else possible. 🔜 Coming up next: The "heavy lifting" begins! I’ll be tackling: 🔹 Get: How to find a value at a specific index (the "walk"). 🔹 Insert: Adding new nodes without breaking the chain. 🔹 Delete: Removing nodes and re-linking the pointers. The goal isn't just to write the code, but to visualize how those pointers shift in memory. 🧠✨ #Day17 #JavaScript #DSA #CodingJourney #LinkedList #LearningInPublic #WebDev #DataStructures #Consistency
To view or add a comment, sign in
-
Back to core DSA algorithms — building from the ground up. 🚀 Today I implemented: 🔹 Selection Sort Algorithm Problem: Sort an array by repeatedly selecting the minimum element and placing it at the correct position. Not the fastest algorithm (O(n²)), but that’s not the point right now. The goal is to understand: ✔ How sorting works internally ✔ How loops and comparisons build logic ✔ Why better algorithms exist Skipping basics is the biggest mistake. I’m not doing that. #DSA #JavaScript #Sorting #Algorithms #CodingJourney #Consistency
To view or add a comment, sign in
-
-
I recently implemented my first Linked List from scratch in JavaScript — no libraries, just raw pointer manipulation. This wasn’t just about writing code; it forced me to understand how data structures actually work under the hood. Here’s what I built: A custom Node structure with value and next pointers Core operations: addAtHead addAtTail addAtIndex deleteAtIndex get What made this interesting wasn’t the syntax — it was the edge cases and pointer management: Handling insertions at head vs tail Maintaining consistent length Avoiding broken references during insertion/deletion Fixing off-by-one errors in traversal Biggest takeaway: Linked Lists are simple in theory, but brutally unforgiving if your pointer logic is even slightly off. This exercise sharpened how I think about: Data structure integrity Boundary conditions Writing predictable, bug-resistant logic Still refining and testing edge cases — but this was a solid step forward. #JavaScript #DataStructures #LinkedList #Coding #SoftwareEngineering #LearningInPublic
To view or add a comment, sign in
-
-
Built an efficient LRU Cache from scratch using JavaScript. Key highlights of the implementation: Designed a custom Doubly Linked List for O(1) insertions and deletions Used a HashMap to achieve constant-time access Ensured optimal eviction strategy by always removing the least recently used node Maintained strict O(1) time complexity for both get and put operations Performance: Runtime: 102 ms (faster than ~57% of submissions) Memory: 113.67 MB This problem reinforced how combining data structures (HashMap + DLL) leads to highly optimized systems — a pattern widely used in real-world caching systems like databases and browsers. Continuing to focus on writing clean, efficient, and scalable code. #DataStructures #Algorithms #JavaScript #SystemDesign #Coding
To view or add a comment, sign in
-
-
Ever changed a variable in JavaScript only to realize you accidentally broke the original data too? 🤦♂️ That’s the classic Shallow vs. Deep Copy trap. Here is the "too long; didn't read" version: 1. Shallow Copy (The Surface Level) When you use the spread operator [...arr] or {...obj}, you’re only copying the top layer. The catch: If there are objects or arrays inside that object, they are still linked to the original. Use it for: Simple, flat data. 2. Deep Copy (The Full Clone) This creates a 100% independent copy of everything, no matter how deep the nesting goes. The easy way: const copy = structuredClone(original); The old way: JSON.parse(JSON.stringify(obj)); (Works, but it’s buggy with dates and functions). The Rule of Thumb: If your object has "layers" (objects inside objects), go with a Deep Copy. If it’s just a basic list or object, a Shallow Copy is faster and cleaner. Keep your data immutable and your hair un-pulled. ✌️ #Javascript #WebDev #Coding #ProgrammingTips
To view or add a comment, sign in
-
-
𝗕𝗲𝘆𝗼𝗻𝗱 𝗚𝗲𝗻𝗲𝗿𝗶𝗰𝘀: 𝗠𝗮𝘀𝘁𝗲𝗿𝗶𝗻𝗴 𝗧𝘆𝗽𝗲𝗦𝗰𝗿𝗶𝗽𝘁'𝘀 𝗔𝗱𝘃𝗮𝗻𝗰𝗲𝗱 𝗧𝘆𝗽𝗲 𝗦𝘆𝘀𝘁𝗲𝗺 𝗳𝗼𝗿 𝗥𝗼𝗯𝘂𝘀𝘁 𝗔𝗽𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻𝘀 Your TypeScript types are not as safe as you think. You use interfaces. You use generics. Your editor shows fewer errors. Yet runtime bugs still appear. Many developers miss advanced type features. These features catch bugs earlier. Here are key features: - Conditional types: add if-then-else logic to types. - The infer keyword: pull types out of functions. Get a function's return type. - Template literal types: check and build string patterns. Use for routes, CSS-in-JS. - Mapped types with as: rename keys. Useful for event handlers. - satisfies operator: validate values against a type without losing literal types. - Branded types: create distinct types from primitives. Avoid mixing IDs. Combine these to build a type-safe API client. The compiler will catch mismatched paths and bodies. These tools remove whole bug categories. Your code becomes more robust. Try one feature this week. Refactor a small part of your code. Notice the improvement. Source: https://lnkd.in/gvzqmNcS
To view or add a comment, sign in
-
Derived state is one of the most subtle sources of bugs. Because it “looks correct”. Until it isn’t. Here’s the issue 👇 You store: → Original data → Derived data (filtered, sorted, computed) Now you have: ❌ Two sources of truth Over time: → They go out of sync → Bugs appear → Debugging becomes painful Example: → items → filteredItems If items update but filteredItems doesn’t… Your UI lies. What works: ✔ Derive data on render (not store it) ✔ Use memoization if expensive ✔ Keep single source of truth Key insight: If something can be derived… It shouldn’t be stored. That’s how you avoid state inconsistency bugs. #ReactJS #StateManagement #Frontend #SoftwareEngineering #JavaScript #AdvancedReact #Architecture #Engineering #Programming #CleanCode
To view or add a comment, sign in
-
People keep asking what tools I use. Here's my exact stack. No affiliate links. No sponsored picks. Just what works. For scripting and core logic: - Python 3.12 — does 90% of everything - Node.js — when I need async performance or browser automation For browser automation and scraping: - Playwright — replaced Selenium completely, faster and more reliable - Bright Data proxies — residential IPs that actually work - 2Captcha — for sites that insist on being difficult For bot development: - python-telegram-bot library — clean API, great docs - Baileys
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