Day 112 of #200DaysOfCode Leveling up Consistency continues, one concept at a time. Today I solved the "Memoize" problem on LeetCode using closures + caching in JavaScript. Key Idea: Avoid recomputing the same function call by storing previously calculated results. Approach: • Use a Map as cache storage • Convert arguments into a unique key using JSON.stringify() • If result already exists return cached value • Otherwise compute, store, and return result Concepts Used: • Closures • Memoization • Map • Higher Order Functions Time Complexity: • First Call → Depends on function • Repeated Calls → O(1) average lookup Space Complexity: O(n) Takeaway: Memoization is a powerful optimization technique that trades space for speed and is heavily used in Dynamic Programming and performance optimization. Learning not just to solve problems — but to make solutions smarter Let’s keep building #Day112 #200DaysOfCode #LeetCode #JavaScript #Memoization #Closures #CodingJourney #ProblemSolving #KeepGoing
Memoization in JavaScript with Closures and Map
More Relevant Posts
-
LeetCode Day 19 : Problem 167 (Two Sum II - Input Array Is Sorted) Just solved my LeetCode problem for today. It was "Two Sum II", sorted array, constant space, find two numbers that add up to a target. Sounds like a simple two-pointer problem, right? But here's what I actually learned: My first instinct was to write three separate while loops, each moving a different pointer in a different direction, thinking I was covering all the cases. I wasn't. The bugs were layered. The first loop only moved the right pointer. The second only moved the left. The third moved both but only toward the center. No single loop ever explored the full space of valid pairs. There was also a check I wrote: if (arr !== undefined) return arr. Looked like a guard. Did absolutely nothing. An empty array is never undefined in JavaScript. The condition was always true and I never noticed. The real fix wasn't patching the loops. It was understanding why the sorted order makes three loops completely unnecessary. The two-pointer solution: start left at index 0, right at the last index. If the sum is too small, move left forward. If the sum is too big, move right backward. One loop, every pair covered, O(n) time, O(1) space. The sorted order is the key insight. It guarantees you never need to backtrack, which is exactly why one clean loop beats three broken ones. The real lesson? When your instinct is to add more loops to cover more cases, stop. Ask whether the structure of the data already tells you which direction to move. Sometimes the constraint in the problem is the solution. #DSA #LeetCode #JavaScript #CodingJourney #Programming
To view or add a comment, sign in
-
-
🚀 Just Uploaded a New LeetCode Solution! Solved LeetCode #26 – Remove Duplicates from Sorted Array using the Two Pointer Technique in JavaScript. This is a must-know pattern for coding interviews — simple idea, but very powerful when applied correctly. 👉 In this video, I’ve covered: Intuition behind the problem Step-by-step dry run Optimal in-place solution (O(n) time, O(1) space) Clean and easy-to-understand JavaScript code 🔗 Watch here: https://lnkd.in/g-HgkGXQ If you're preparing for coding interviews or strengthening your DSA fundamentals, this one is definitely worth your time. Would love to hear your approach to this problem — drop it in the comments 👇 #leetcode #dsa #codinginterview #javascript #twopointer #programming #softwaredevelopment #coding #developers #learning #jdcodebase
Remove Duplicates from Sorted Array | Optimal Two Pointer Approach 🔥 | LeetCode Explained (JS)
https://www.youtube.com/
To view or add a comment, sign in
-
📘 Big O Notation I’ve been spending some time understanding Big O Notation — it felt confusing at first, but it’s becoming clearer little by little. Big O is a way to understand how efficient our code is as the input size grows. It’s not about exact speed, but about how well an algorithm scales. 💡What I practiced: • Learned the basics like O(1), O(log n), O(n), and O(n²) • Compared how arrays and sets behave in different operations • Used simple loops, map, and forEach to see how performance changes • Wrote small examples to better understand the differences 🧠 My takeaway: Just because code works doesn’t mean it’s efficient. Thinking about performance from the beginning really matters. Still learning, but getting more comfortable with these concepts. #BigONotation #TimeComplexity #CodingJourney #JavaScript #LearningEveryday
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
-
-
🌞 Back to LeetCode 75 – Day 43 ✅ 841. Keys and Rooms After a short break, I’m getting back into my daily problem-solving routine. Today’s problem was about checking whether we can visit all rooms starting from room 0, where each room contains keys to other rooms. Approach : This is basically a graph traversal problem in disguise. - Each room = a node - Keys = edges to other nodes So the task becomes: - Can we reach all nodes starting from node 0? I used an iterative DFS with a stack: - Start from room 0 - Use a visited array to track visited rooms - Keep exploring using available keys - Push unvisited connected rooms into the stack Complexity : - Time: O(N + K) - Space: O(N) Key Takeaway : Once you recognize this as a graph problem, the solution becomes straightforward. This is a good reminder that many array-like problems are actually graph problems in disguise. Restarting the consistency journey again — one problem at a time. 🚀 #LeetCode75 #Day43 #DSA #JavaScript #Graph #DFS #ProblemSolving #Coding #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 2 of Logic Building in JavaScript Most beginners ignore this… but pattern problems actually build real programming logic 🤯 Today I focused on strengthening my fundamentals through pattern-based questions 👇 ✅ What I practiced: • Right-angled star pattern • Inverted right-angled star pattern • Pyramid star pattern • Diamond shape ⭐ & inverted pattern (odd numbers) • Hollow square star pattern • Hollow pyramid triangle • Alternate binary triangle (0-1 pattern) 🧠 What I actually learned: • How 2*i - 1 controls pyramid width • How spacing (n - i) creates perfect alignment • Difference between boundary vs inner logic in hollow patterns • Importance of print vs println (small thing, big impact!) Consistency 💯 Building logic one day at a time 🚀 👉 What was the toughest pattern you faced while learning? #Day2 #LogicBuilding #JavaScript y #DSA #100DaysOfCode #LearnInPublic #Developers
To view or add a comment, sign in
-
59.8 MB JavaScript source leak of Claude Code. Surprisingly, it was a human error that happened during the release packaging. No customer data, API credentials, or model weights were exposed. But, 512,000 lines of TypeScript across ~1,900 files were exposed. It includes the query engine, tool system, multi-agent orchestration logic, and context compaction. But the amazing part? Someone noticed this as an opportunity. The guy's name is Sigrid Jin, a Korean Developer. He developed Claw Code, a clean-room Python rewrite of Claude Code's agent harness. He published it on GitHub where the repo reached 50k stars in just 2 hours. If you want the GitHub URL, comment "Claw Code" and I will share it with you.
To view or add a comment, sign in
-
-
LeetCode Day 21 : Problem 209 (Minimum Size Subarray Sum) Just solved my LeetCode problem for today. It was "Minimum Size Subarray Sum", find the shortest contiguous subarray whose sum is greater than or equal to a target. My first approach was trying to trim the array from both ends. Remove elements from the front if the sum still holds, then figure out the length at the end. It felt logical in my head but it failed on most test cases and I couldn't immediately see why. The bugs were deeper than I expected. The first one was a JavaScript gotcha that had nothing to do with the algorithm. I wrote newArr = nums thinking I was making a copy. I wasn't. Both variables pointed to the same array in memory, so when I called shift() on newArr, I was also mutating nums mid-loop. The loop was iterating over an array that was shrinking underneath it, silently skipping elements. The second issue was the trimming logic itself. I was only ever looking at the first element when deciding what to remove. That is not how you find a minimal window. You need to consider every possible left boundary, not just the front of the array at that moment. The third was a line I wrote thinking it was doing something: newArr.unshift() with no argument. It adds nothing, returns the length, and the result goes nowhere. Completely dead code that I mistook for a shrink operation. The correct approach is a dynamic sliding window. Expand the right pointer freely. The moment your window sum meets the target, record the length and shrink from the left. Keep shrinking as long as the condition still holds. The smallest window you ever record is your answer. The subtle difference from a longest-window problem is where you record the answer. Here it goes inside the shrink loop, before you remove the left element, because you want the smallest valid window not the largest. The real lesson? Mutating an array while iterating over it is one of the most silent bugs in JavaScript. Always copy with slice or spread when you need an independent array. #DSA #LeetCode #JavaScript #CodingJourney #Programming
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
-
-
JavaScript array methods visualized with Pokémon. I’ve been experimenting with short visual loops using Claude Code and Remotion to explain concepts faster and this one shows some of the most common array methods in practice. Quick reference using real behavior: • filter() selects matching items • map() transforms items • find() returns the first match • findIndex() returns the index of the match • fill() replaces values • every() checks all items • some() checks at least one • concat() merges arrays • includes() checks existence • push() adds to the end • pop() removes from the end • shift() removes from the start • unshift() adds to the start • splice() removes or replaces items Same concepts, just easier to visualize. #javascript #webdev #frontend #coding #programming
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