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
Optimizing JavaScript for Memory and Speed
More Relevant Posts
-
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
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
-
🚀 Day 6/100 – #100DaysOfDSA Today’s focus was on searching vs sorting and understanding efficiency differences. 🔹 Problems Solved: 1. Binary Search 2. Bubble Sort 💡 Key Learnings: 👉 Problem 1: Binary Search Works only on sorted arrays Divide the search space into half each time 👉 Approach: Find mid index Compare with target Move left or right accordingly ✅ O(log n) Time Complexity ✅ Very efficient for large datasets 👉 Problem 2: Bubble Sort Most people implement Bubble Sort, but today I learned how to optimize it using an early break condition 🚀 👉 Approach: If no swaps happen in a pass, the array is already sorted — so we can stop early instead of continuing unnecessary iterations. ✅O(n) (Optimized with swap flag) 🔥 What I learned today: Choosing the right algorithm matters more than just solving the problem. Consistency continues 💪 Day 6 done! #100DaysOfCode #DSA #BinarySearch #Sorting #LeetCode #ProblemSolving #CodingJourney #JavaScript #TechGrowth #SoftwareEngineer #LearningInPublic
To view or add a comment, sign in
-
🌞 Day 44 – LeetCode 75 ✅ 547. Number of Provinces Today’s problem was about finding how many connected components (provinces) exist in a graph represented using an adjacency matrix. Approach : I treated the matrix as a graph problem: - Each city = a node - isConnected[i][j] = 1 means there is a connection (edge) So the goal becomes: - Count how many disconnected groups exist. DFS Approach : - Maintain a visited[] array to track visited cities Loop through each city: - If not visited → it means a new province - Run DFS to mark all cities connected to it Complexity : - Time: O(n²) → because we scan adjacency matrix - Space: O(n) → visited array + recursion stack Key Insight : This is a classic Connected Components in Graph problem. Even though it looks like a matrix problem, it’s really: - How many disconnected graphs exist? Once you see that pattern, DFS/BFS becomes very natural. Restarting consistency again — building momentum one graph problem at a time 🚀 #LeetCode75 #Day44 #LeetCode #DSA #JavaScript #Graph #DFS #ConnectedComponents #ProblemSolving #Coding #LearningInPublic #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
-
-
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
-
-
🚀 Solved: Valid Parentheses (Stack Based Problem) Today I worked on a classic problem that looks simple but tests your core logic 👇 🧠 Problem: Given a string containing only (), {}, [] 👉 Check if the parentheses are valid 💡 Approach I used: Used a stack Push opening brackets For closing brackets: Check top of stack If match → pop Else → invalid ⚙️ Key Insight: 👉 Order matters more than count 👉 Stack helps track the sequence correctly 🔥 What I learned: Importance of stack in real problems Handling edge cases (empty stack, mismatch) Writing clean conditional logic 📌 Time Complexity: O(n) 📌 Space Complexity: O(n) 💬 Have you solved this problem differently? Would love to know your approach! #javascript #cpp #datastructures #algorithms #coding #leetcode #interviewprep
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
-
-
The Cursed Cycle of Legacy Code 💀 Ah, the eternal struggle: developers clinging to their archaic frameworks like a cursed spirit to a dilapidated vessel. You chase the latest JavaScript fad, the 'revolutionary' new Python library, yet your backend still groans under the weight of code written when 'responsive design' meant making sure your tables didn't break on Netscape Navigator. Fools. True mastery isn't about adopting every shiny new toy. It's about understanding the fundamental curses of abstraction and dependency, knowing when to refactor with precision, and when to burn it all down and rebuild from the ashes. Many seek the 'perfect' stack, hoping it will cleanse their sins of technical debt. There is no such salvation. Only diligent refactoring, rigorous testing, and the occasional strategic 'Domain Expansion: Production Redeployment' to purge the old demons. Stop chasing ghosts. Confront your legacy. Or drown in its entropy. — The King of Curses
To view or add a comment, sign in
Explore related topics
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