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
LRU Cache Implementation in JavaScript
More Relevant Posts
-
Difference between fundamental data structures used in JavaScript: - If you need to access items by index, you should probably be using an Array. - If you need to access items by key, you should probably be using an Object. - If you need to access items by value, you should probably be using a Map. - If you need to store unique items and perform operations on that collection, you should probably be using a Set. #javascript #concepts #developer #coding #engineer
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
-
Still using complex RegExp for URL matching in JavaScript? There’s a cleaner way. The URLPattern API makes it easy to match routes, extract params, and validate URLs using readable patterns instead of hard-to-maintain regex. Useful for: • custom routers • analytics tracking • access control rules • microfrontend routing • extracting dynamic route params Cleaner syntax. Fewer bugs. Better readability. Worth adding to your modern JavaScript toolkit. #javascript #webdevelopment #frontenddevelopment #modernjavascript #webdevtips #softwareengineering #browserapis #codingtips #devcommunity #reactjs #microfrontend
To view or add a comment, sign in
-
-
Today I finally understood how JavaScript actually stores data in memory — and it changed the way I look at code. Earlier, I used to just write variables and functions without thinking much about what’s happening behind the scenes. But now it makes a lot more sense: Primitive values (like numbers, strings, booleans) are stored directly in memory Reference types (like arrays and objects) are stored differently — the variable holds a reference, not the actual value That’s why things like this behave unexpectedly sometimes: Copying objects doesn’t create a real copy Changing one reference can affect another Understanding this cleared up a lot of confusion I had while debugging. Still learning, but this felt like a small breakthrough Hitesh Choudhary Piyush Garg Chai Code #JavaScript #WebDevelopment #100DaysOfCode #LearningInPublic
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
-
-
Day 1/75 Blind 75 DSA Challenge - Two Sum (LeetCode #1) Problem: Given [2,7,11,15] and target 9, return indices [0,1] Brute Force (O(n²)): Check every pair Optimal (O(n)): Hashmap stores target - nums[i] javascript function twoSum(nums, target) { const seen = {}; for(let i = 0; i < nums.length; i++) { let complement = target - nums[i]; if(seen[complement] !== undefined) { return [seen[complement], i]; } seen[nums[i]] = i; } } Key Learning: Hashmaps turn O(n²) → O(n). Dry-ran on paper: [3,2,4] target 6 → [1,2] Tracker: ✅ 1/75 problems Next: Arrays Day 2 tomorrow #DSA #LeetCode #Blind75 #JavaScript #InterviewPrep #Frontend
To view or add a comment, sign in
-
Backtracking: Combination Sum Problem Day 4 👈 Problem: - Given an array of numbers and a target value, find all unique combinations where the numbers sum up to the target. 🧠 Summary (Simple Understanding) Think of it like: "Pick a number → reduce target → try again → backtrack → try next number" This pattern helps you explore all possibilities efficiently without duplicates. #DataStructures #Algorithms #Backtracking #Recursion #TypeScript #JavaScript #CodingInterview #DSA #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Generate All Unique Subsets Day 3 👈 - First, sort the array - While generating subsets, skip duplicate elements at the same recursion level - This approach uses backtracking to explore all subset possibilities while maintaining uniqueness. Key Idea Use backtracking to build subsets step by step Add the current subset (path) to the result at every step Skip duplicates using: if (i > start && nums[i] === nums[i - 1]) continue; 👉 Time Complexity: O(2ⁿ) 👉 Space Complexity: O(n) (excluding result) #Subsets #PowerSet #Combinatorics #DuplicateHandling #DFS #Backtracking #Recursion #DSA #Algorithms #Subsets #PowerSet #LeetCode #ProblemSolving #CodingInterview #JavaScript #TypeScript #Angular
To view or add a comment, sign in
-
-
🚀 DSA Learning (Realization while solving Top K Frequent Elements) My initial approach was simple: 👉 Count frequency of each number using a HashMap 👉 Then compare frequency with k and push elements into a result array But then I got stuck… ❓ I tried to use .map() directly on the HashMap — and it didn’t work That’s when I realized: - Map is not an array, so array methods like .map() won’t work on it - What actually works: First convert the map into an array 👇 Array.from(map.entries()) Then: ✔️ sort by frequency ✔️ take top k ✔️ extract elements That small shift in understanding made the whole problem click 💡 #DSA #JavaScript #CodingJourney #LeetCode
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