🚀 Day 11/30 of My JavaScript Challenge Solved LeetCode 2623 - Memoize ✅ 💡 What I Learned Today: 🔹 Caching results to optimize repeated function calls 🔹 Using closures to preserve cache data 🔹 Handling multiple arguments with JSON.stringify() 🔹 Using apply() to pass arguments dynamically 🧠 Approach: Created a wrapper function that stores previously computed results in a cache object. If the same arguments are passed again, it returns the cached result instead of executing the function again. ⏱️ Complexity: ⚡ Time: O(1) for cached calls, depends on function for new calls 💾 Space: O(n) for storing cached results 🎥 Watch my full explanation on YouTube: 👉 https://lnkd.in/gqyRQpGT Every challenge is sharpening my JavaScript fundamentals step by step. 🔥 #JavaScript #LeetCode #CodingChallenge #WebDevelopment #FrontendDeveloper #ProblemSolving #YouTube #Programming
Memoizing LeetCode 2623 with JavaScript Caching
More Relevant Posts
-
LeetCode Day 20 : Problem 15 (3Sum) Just solved my LeetCode problem for today. It was "3Sum", find all unique triplets in an array that add up to zero. Sounds like a natural extension of Two Sum, right? Just add a third pointer. But here's what I actually learned: The naive extension doesn't work cleanly. Three nested loops give you O(n³) and you still have to deduplicate the output, which becomes its own problem. The real insight is that sorting first unlocks everything else. Once the array is sorted, you fix one number with an outer loop and reduce the remaining problem to exactly Two Sum II on the rest of the array. Two pointers, moving inward, same logic as yesterday. O(n²) total, one pass per fixed element. But the deduplication is where this problem actually lives. There are three places duplicates can sneak in and each needs its own guard. The first is the outer pointer. If nums[i] equals nums[i-1], you've already explored every triplet that starts with this value. Skip it. The second and third are the inner pointers after finding a valid triplet. If nums[left] equals nums[left+1], moving left forward once would just find the same triplet again. Same for the right side. So you skip past all consecutive duplicates before moving both pointers inward. The order of those inner skips matters too. You skip duplicates first, then move the pointers. Not the other way around. Sorting is doing most of the heavy lifting here. It makes the two-pointer approach possible, it makes duplicate detection trivial with a single comparison, and it guarantees that once your fixed element is positive, no valid triplet can exist ahead of it since two positives can never sum to zero with another positive. The real lesson? Sorting is often the unlock that turns an ugly O(n³) problem into a clean O(n²) one. Before writing nested loops, ask whether sorting the input first changes what's possible. #DSA #LeetCode #JavaScript #CodingJourney #Programming
To view or add a comment, sign in
-
-
Today I learned one of the most important basics in JavaScript — how to declare variables 💻 I practiced using: ✔️ var ✔️ let ✔️ const 🔹 var – old way (function scoped) 🔹 let – modern & block scoped 🔹 const – used for values that shouldn’t change I also understood: ✅ How to store data in variables ✅ How to print values using console.log() ✅ The difference between reassigning variables ✅ Block scope behavior Small steps, but strong foundation 💪 Consistency is the key 🔑 — aiming to code daily and improve step by step. #JavaScript #FrontendDevelopment #CodingJourney #100DaysOfCode #WebDevelopment #Learning #BeginnerDeveloper
To view or add a comment, sign in
-
-
LeetCode Day 15 : Problem 14 (Longest Common Prefix) Just solved another LeetCode problem. It was "Longest Common Prefix", sounds simple, right? But here's what I actually learned: My first solution used for...in to loop over the array. It worked but for...in is designed for objects, not arrays. It iterates over enumerable properties and can cause unexpected bugs if anything is added to Array.prototype. Always use for...of for arrays and for...in for objects. The approach itself was clean, start with the first string as the prefix, then shrink it character by character whenever a mismatch is found. By the end, whatever is left is the longest common prefix. The insight that made it click, you don't need to compare all strings against each other. Just keep shrinking one reference prefix until every string agrees with it. Seventeen problems in. JavaScript has many ways to loop, for, for...of, for...in, forEach. Each has a specific purpose. Using the wrong one can work most of the time but fail in edge cases. Know the difference. The real lesson? Just because it works doesn't mean it's right. Always use the tool designed for the job. #DSA #LeetCode #JavaScript #CodingJourney #Programming
To view or add a comment, sign in
-
-
🚀 What I Learned Today in JavaScript Today’s learning was focused on strengthening my core fundamentals and improving my logical thinking in JavaScript. 🔹 What I Learned: • Understanding the flow of if, else if, and else conditions • Difference between return and console.log() (and why functions return undefined) • Practical use of logical operators: &&, ||, ! • Using switch-case for handling multiple conditions efficiently • Implemented logic for real-world problems: Rock Paper Scissors game Login system (User vs Admin conditions) Age category checker 🔹 Challenges I Faced: • Confusion between return and console.log() • Understanding how multiple conditions execute (flow of control) • Handling edge cases while writing logic • Writing clean and structured conditional statements 🔹 How I Solved Them: • Practiced writing multiple small programs instead of just reading concepts • Broke problems into smaller steps and solved them one by one • Tested different inputs to understand behavior deeply • Focused on logic building instead of memorizing syntax #javascript #webdevelopment #codingjourney #100daysofcode #developer #learncoding #frontend #programming #logicbuilding
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
-
-
I spent the last few days cleaning up some of the mess in my "Fastapi-Ecosystem-Lab" repo. Even though the frontend was already working, I knew that if I didn't set a solid foundation now, my "future self" would absolutely hate me—it would’ve been impossible to maintain any kind of team standard otherwise. I finally got Vitest dialed in, with full coverage on the parts that worried me most, like form validation and route security. Now that GitHub Actions are set up, I can breathe easier knowing that if I break something in the tests or the linter, the error gets caught in the pipeline and never hits the main branch. I also decided to pull the trigger on Next.js 16 (canary) and React 19. Getting the types right with Zod v4 and the new Server Actions took a bit of trial and error, but those cache optimizations are definitely worth it. Plus, I automated import and Tailwind class sorting—it sounds like a small thing, but it makes the code so much easier to read. You can check out the full repo here: https://lnkd.in/eqimu-qx Anyone else running into hydration issues with the latest React 19 and Next.js builds? I had a few headaches yesterday dealing with client components.
To view or add a comment, sign in
-
💻 Day 1 of Coding Today I practiced JavaScript fundamentals and solved some problems: • Calculated average marks from an array • Applied 10% discount on item prices using loops • Worked with arrays (adding, removing, replacing elements) • Created functions to count vowels in a string (normal + arrow function) • Practiced if-else and loop-based questions While solving these, I did face some difficulties understanding the logic at first, but after thinking through the problems step by step, I was able to figure them out. What I learned: Better understanding of loops and arrays How to manipulate data inside arrays Writing cleaner logic step by step Small progress, but staying consistent 🚀 #JavaScript #100DaysOfCode #WebDevelopment
To view or add a comment, sign in
-
Leetcode Day 1 : Problem 1 (Merge Sorted Array) Just solved my first LeetCode problem. It was the classic "Merge Sorted Array" sounds simple, right? But here's what I actually learned: JavaScript's .sort() doesn't sort numbers by default, it sorts them as strings. [1, 10, 2] becomes [1, 10, 2] not [1, 2, 10]. A one-line bug that would fail silently. Reassigning an array variable (arr = []) doesn't modify the original. LeetCode wants in-place changes. That took me a moment. I was filtering out zeros thinking they were empty slots, but 0 is a perfectly valid element. Hidden test cases would've caught me. Three bugs. One "easy" problem. Tons of learning. The real lesson? Passing the visible test cases doesn't mean your code is correct. Always think about edge cases. If you've been putting off starting DSA Interview questions like I was just open problem 1 and start. The first step is the hardest. #DSA #LeetCode #JavaScript #CodingJourney #Programming
To view or add a comment, sign in
-
-
JavaScript is single threaded, but handles async operations so smoothly 👇 That’s where the Event Loop comes in. At first, things seem simple: • Code runs line by line But then you see behavior like this: Even with 0ms, the timeout doesn’t run immediately. Because JavaScript uses: ✔ Call Stack ✔ Web APIs ✔ Callback Queue ✔ Event Loop Understanding this changed how I think about async code and debugging. Sometimes the delay isn’t about time, it’s about how the event loop schedules execution. #JavaScript #EventLoop #AsyncJavaScript #FrontendDevelopment #Programming
To view or add a comment, sign in
-
-
Closures in JavaScript felt confusing, until they didn’t 👇 At first, it’s hard to understand how a function can “remember” variables even after execution. But that’s exactly what closures do. A closure is created when a function retains access to its lexical scope, even after the outer function has finished executing. Even though `outer()` has finished execution, the inner function still has access to `count`. That’s the power of closures. They are widely used for: • Data encapsulation • Maintaining state • Creating reusable functions Understanding closures makes many JavaScript patterns much clearer. #JavaScript #Closures #FrontendDevelopment #SoftwareEngineering #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