A good practice for expensive (slow or repeated) computations is to use memoization, which stores the results so that any time they are needed again with the same input, the function instantly returns the cached result instead of redoing the work. talk of Math functions such as Fibonacci, factorial, primes; API calls to avoid repeat network requests thus less latency and cost; Image processing to cache filters or resizing or in data analytics to cache metrics or aggregate. Attached is a memoization example #JavaScript #FunctionalProgramming #CleanCode #SoftwareEngineering #SoftwareDevelopment #SoftwareTips #letsconnect #buildinpublic
How to speed up computations with memoization
More Relevant Posts
-
🔗 Day 154 of 160 – GeeksforGeeks #gfg160 DSA Challenge 📌 Problem: Implement Trie (Prefix Tree) 💻 Language: JavaScript 📂 Topic: Trie | Strings | Data Structures 🧠 Problem Summary: Implement a Trie data structure that supports three main operations: insert(word) – Add a word into the Trie. search(word) – Check if the exact word exists. startsWith(prefix) – Check if any word starts with the given prefix. ✅ Approach Used: Trie (Prefix Tree) Implementation using Node Class Create a TrieNode class containing: A map (children) to store next characters. A boolean isEnd to mark the end of a word. In the Trie class: insert(word): Traverse character by character, creating new nodes if missing. search(word): Traverse through nodes; return true only if isEnd is true at the end. startsWith(prefix): Traverse like search, but return true as long as the prefix exists. ⏱ Time Complexity: Insert: O(L) Search: O(L) StartsWith: O(L) (where L = length of the word/prefix) 📦 Space Complexity: O(N × M) (where N = number of words, M = average word length) 🔍 Key Insights: Trie efficiently stores strings with shared prefixes, reducing redundancy. Ideal for autocomplete, spell check, and prefix-based searching. A must-know data structure for string-heavy applications. 💡 Takeaway: Building a Trie reinforces how structured prefix storage can make string lookups extremely fast — a vital concept in text processing and search engines. #Day154 #DSAChallenge #Trie #PrefixTree #StringDSA #GeeksForGeeks160 #JavaScriptDSA #Autocomplete #DataStructures #CodingChallenge #160DaysOfCode #AlgorithmLearning #ProblemSolvingDaily #TechInterviewPrep #SearchOptimization
To view or add a comment, sign in
-
-
After solving 500+ LeetCode questions, I concluded: · Linked List · If you can draw the solution with paper and pen, you can code it. · Trees · If you have a command of recursion, you can solve it. The only things you need are a base case and a recurrence relation. · Sliding Window · When you get the feeling of comparing two strings at each step, go with it. You only need a hashmap and a comparison function. · Binary Search · If you know anything is sorted, or you get the feeling of eliminating half of the input set in a divide-and-conquer manner, go ahead with it. · Stack · When you need to track elements for a later comparison or reverse the order of processing, use this data structure. #leetcode #dsa #datastructure #algorithms
To view or add a comment, sign in
-
-
I’ve been consistently practicing Data Structures & Algorithms, focusing on understanding the underlying logic and core patterns behind each problem rather than just solving them. Here’s a summary of some recent problems I’ve tackled, along with the key concepts learned 📌 225. Implement Stack using Queues Key Concept: Queue-based simulation of stack operations (using two queues or a single optimized queue) https://lnkd.in/gabQrA_R 📌232. Implement Queue using Stacks Key Concept: Stack-based implementation using two stacks — one for enqueue, one for dequeue operations https://lnkd.in/gwq44Akm 📌102. Binary Tree Level Order Traversal Key Concept: Breadth-First Search (BFS) using a queue for level-wise traversal of binary trees https://lnkd.in/gn4ejwNK 📌239. Sliding Window Maximum Key Concept: Deque-based sliding window to efficiently track the maximum element in each window https://lnkd.in/gwDAFZkP 📌435. Non-overlapping Intervals Key Concept: Sorting by end time + greedy interval selection to minimize overlaps https://lnkd.in/gVwP-2pf 📌1710. Maximum Units on a Truck Key Concept: Greedy approach inspired by the knapsack problem — maximize total units by sorting on value https://lnkd.in/gqxdifBu 📌646. Maximum Length of Pair Chain Key Concept: Similar to non-overlapping intervals — greedy selection based on the smallest end time https://lnkd.in/gik6pJ6K These problems helped me strengthen concepts like queue–stack interconversion, BFS traversal, sliding window optimization, greedy algorithms, and interval scheduling techniques. I’d highly recommend trying these problems out — they’re great for building pattern recognition and problem-solving intuition. Here’s my LeetCode Profile for reference: https://lnkd.in/gp38YMN7 #DSA #LeetCode #Java #Algorithms #ProblemSolving #CodingInterview #SoftwareDevelopment #SDE #TechJourney #DailyCoding
To view or add a comment, sign in
-
-
🔥 Day 115 of My DSA Challenge – Intersection of Two Arrays II 🔷 Problem : 350. Intersection of Two Arrays II 🔷 Goal : Return the intersection of two arrays, where each element in the result must appear as many times as it shows in both arrays. Order doesn’t matter. 🔷 Key Insight : This is an extension of the previous problem (Intersection of Two Arrays). The twist? Here we need to consider duplicate occurrences too. For example : nums1 = [1,2,2,1], nums2 = [2,2] → result should be [2,2] (because 2 appears twice in both). 🔷 Approach : 1️⃣ Use a HashMap to count occurrences of each element in nums1. 2️⃣ Traverse nums2 and check if an element exists in the map. 3️⃣ If yes → add it to the result and decrease its count in the map. 4️⃣ When the count becomes 0, remove it from the map to keep things clean. Time Complexity: O(n + m) Space Complexity: O(n) This problem strengthens hash-based frequency counting and element tracking. Use a map to record frequency — then match, decrease, and clean up. This logic is key for : ✅ Counting duplicates ✅ Array frequency comparison ✅ Inventory & matching systems Every small concept compounds into bigger problem-solving clarity. Step by step, I’m becoming stronger at thinking like a coder 💪💻 #Day115 #DSA #100DaysOfCode #HashMap #LeetCode #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #DeveloperJourney #LogicBuilding #EngineerMindset #GrowEveryday
To view or add a comment, sign in
-
-
🔍 Day 66 of #100DaysOfCode 🔍 🔹 Problem: Binary Search – LeetCode ✨ Approach: Implemented an iterative binary search to efficiently locate the target element within a sorted array. By halving the search range each time — adjusting low and high around the mid-point — the algorithm achieves blazing-fast lookups! ⚡ 📊 Complexity Analysis: Time Complexity: O(log n) — array size halves with each iteration Space Complexity: O(1) — constant extra space ✅ Runtime: 0 ms (Beats 100.00%) ✅ Memory: 46.02 MB 🔑 Key Insight: Binary Search is proof that efficiency isn’t about doing more — it’s about eliminating what’s unnecessary. 🚀 #LeetCode #100DaysOfCode #ProblemSolving #DSA #AlgorithmDesign #BinarySearch #LogicBuilding #Efficiency #ProgrammingChallenge #CodeJourney #CodingDaily
To view or add a comment, sign in
-
-
🔥 Day 116 of My DSA Challenge – Move Zeroes 🔷 Problem : 283. Move Zeroes 🔷 Goal : Move all 0s to the end of the array while maintaining the relative order of non-zero elements. Must be done in-place without using extra space. 🔷 Key Insight : This problem focuses on in-place array manipulation and pointer logic. We need to keep all non-zero elements in front and shift all zeros toward the end — but without disturbing their relative order. A simple and efficient solution is to use the two-pointer approach: One pointer (idx) scans through the array. Another pointer (k) keeps track of where the next non-zero should be placed. 🔷 Approach : 1️⃣ Initialize pointer k = 0 2️⃣ Traverse the array with index idx 3️⃣ If nums[idx] != 0, assign nums[k] = nums[idx] If k != idx, set nums[idx] = 0 to push zero backward Increment k 4️⃣ The array is now rearranged in-place Time Complexity: O(n) Space Complexity: O(1) This problem strengthens array manipulation and in-place optimization skills. Use pointers wisely — move only what’s needed, keep it clean, keep it fast. This logic is useful for : ✅ Partitioning problems ✅ Rearranging arrays ✅ In-place sorting optimizations Another small but meaningful win — one step closer to mastering the art of clean, efficient code 🚀 #Day116 #DSA #100DaysOfCode #LeetCode #TwoPointers #Arrays #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #DeveloperJourney #EngineerMindset #LogicBuilding #GrowEveryday
To view or add a comment, sign in
-
-
💡 Problem-Solving Post: Surrounded Regions in a Grid Today I worked on an interesting problem that really tested my understanding of graph traversal and boundary conditions. 🧩 Problem Summary: Given a 2D grid containing 'O's and 'X's, the goal is to replace all 'O's that are completely surrounded by 'X's. In other words, any 'O' that is not connected to the border should be converted into 'X'. ⚙️ Key Idea: At first glance, it looks like a simple replacement problem — but it’s not! The challenge is to differentiate between ‘O’s that are truly surrounded and those that are connected to the border. 🧠 Approach: Identify all 'O's on the borders (they can never be surrounded). From each border 'O', perform a DFS/BFS traversal to mark all connected 'O's as “safe.” After marking, flip the remaining 'O's (which are not safe) into 'X'. 🚀 What I Learned: The importance of thinking beyond the direct condition — sometimes the solution lies in what’s connected to the edge. How depth-first or breadth-first traversal can simplify problems that initially seem complex. A reminder that clean logic and clear reasoning often matter more than complex code. 👨💻 Complexity: Time: O(n × m) Space: O(n × m) (due to recursion or queue storage) It’s a simple yet elegant application of graph traversal that blends problem-solving and optimization thinking. Have you solved a similar boundary-based traversal problem recently? Would love to hear your approach or variations! #ProblemSolving #DSA #GraphAlgorithms #CodingJourney #LearningEveryday #Java
To view or add a comment, sign in
-
-
HashMap / Frequency Map Pattern — A Simple Way to Make Many Problems Easier One of the most helpful patterns in DSA is using a HashMap (or dictionary) to store frequencies, counts, and relationships. It sounds basic, but once you start using it properly, it simplifies a huge number of array and string problems. Many challenges become easier when you track: 1. How many times does something appear 2. whether two elements match 3. whether a pattern exists 4. or which elements you’ve already seen HashMaps help you avoid unnecessary loops and give you instant lookups in O(1) time. Where This Pattern Shines You can use HashMaps to handle: 1. frequency of characters 2. frequency of numbers 3. mapping relationships (like original → index) 4. tracking visited pairs 5. Comparing two strings 6. counting subarrays This tiny tool solves big problems. Examples You Can Try 1. Two Sum (LeetCode 1) https://lnkd.in/dUgJH-Ss Store numbers in a map as you go. Instant complement lookup instead of nested loops. 2. Valid Anagram (LeetCode 242) https://lnkd.in/dzaRRedB Compare frequency maps of both strings. Clear and direct. 3. Top K Frequent Elements (LeetCode 347) https://lnkd.in/dCm6CcDt Count frequencies first, then use a heap/bucket approach. 4. Subarray Sum Equals K (LeetCode 560) https://lnkd.in/d9fWhG7B Prefix sum + frequency map. Efficient and elegant. 5. Group Anagrams (LeetCode 49) https://lnkd.in/dUzJ_kgX Hashing sorted strings or character counts creates natural groups. Why This Pattern Helps Others Too This is one of the easiest patterns to understand, and it gives a huge confidence boost because: • solutions become cleaner • the approach becomes predictable • you stop writing expensive nested loops • and the overall logic feels more organized Once you start spotting places where a HashMap can store helpful data, many “hard” questions suddenly feel manageable. #DSA #CodingPatterns #LeetCode #CodingJourney #LearningInPublic #SoftwareEngineering #ProblemSolving #CleanCode #DeveloperMindset #SDEJourney #TechCommunity
To view or add a comment, sign in
-
🚀 Two Pointer Technique — The Hidden Gem of Optimized Problem Solving The Two Pointer technique is one of those elegant patterns that transforms nested loops into clean O(n) solutions. It’s all about using two indices that move through your data — sometimes from opposite ends, sometimes together — to efficiently compare, partition, or traverse arrays and strings. Whether it’s finding pairs with a target sum, removing duplicates in-place, or checking for palindromes, the principle stays the same: 👉 Use movement, not brute force. Instead of restarting the search every time, the Two Pointer method lets you reuse previously processed data, dramatically reducing unnecessary computations. From array problems to linked lists, and even complex challenges like “Container With Most Water” or “3Sum,” mastering this pattern unlocks a new level of clarity and performance in your problem-solving approach. Follow Codekerdos for more algorithm deep-dives, clean code patterns, and practical insights that sharpen your developer mindset 🔥 #Algorithms #TwoPointer #ProgrammingTips #DeveloperMindset #Codekerdos #CleanCode #SoftwareEngineering #100DaysOfCode #google
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