Subarray Sum Equals K - Leetcode 560 - In Hindi
Автор: LazyCoder
Загружено: 2025-06-19
Просмотров: 9
Описание:
📌 Leetcode 560 – Subarray Sum Equals K
In this video, we solve one of the most asked array problems using an efficient prefix sum + hashmap technique. The task is to find the total number of continuous subarrays that sum to a given k.
👨💻 What You’ll Learn:
Brute force vs optimized approach
How to use prefix sums to avoid nested loops
Smart use of hashmaps to track cumulative sums
🧠 Time Complexity Analysis:
🔸 Brute Force:
⏱️ O(n²) – Check every subarray sum with nested loops
🔸 Optimized (Prefix Sum + HashMap):
⏱️ O(n) Time | O(n) Space – Single pass using a running sum and hashmap
💡 Key Insight:
Instead of checking all subarrays, keep track of how many times a prefix sum has occurred. If curSum - k exists in the hashmap, you've found a valid subarray ending at the current index.
🔗 Problem Link:
https://leetcode.com/problems/subarra...
💬 Comment if you’ve seen this trick before, or if it was new for you!
#codinginterviewprep #hashmap #pythoncoding4u #DataStructures #algorithmsecrets #LeetcodeSolution #TechInterviewPrep #dsarmyvlogs #problemsolvingskills #codingchallenge #arrayproblems #codewithme
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: