Solved LeetCode #560 with Hash Map and Prefix Sum

Day 35 / 100 – Subarray Sum Equals K (LeetCode #560) Today’s challenge was about finding the number of continuous subarrays whose sum equals a given value k. At first, the brute-force approach felt tempting — checking every possible subarray — but that would be too slow. Instead, I learned to use a Hash Map to store cumulative sums and find the solution in linear time. This problem truly deepened my understanding of prefix sums and how storing previous computations can make complex problems simple and elegant. 🔍 Key Learnings Prefix Sum helps keep track of cumulative totals efficiently. Hash Maps allow quick lookups, reducing time complexity from O(n²) to O(n). Sometimes, the key to optimization is remembering what you’ve already calculated. 💭 Thought of the Day Today reminded me that not every problem needs to be solved from scratch — sometimes, the best solutions come from building on what you already know. Logic and memory, when used together, create magic in code ✨ 🔗 Problem Link: https://lnkd.in/gVGGGm6J #100DaysOfCode #Day35 #LeetCode #Python #HashMap #ProblemSolving #DataStructures #Algorithms #CodingChallenge #CodeEveryday #LearningJourney #Optimization #CleanCode #TechGrowth

  • graphical user interface

To view or add a comment, sign in

Explore content categories