LeetCode Challenge: Solved Continuous Subarray Sum with Prefix Sum & HashMap

𝗗𝗮𝘆 𝟱/𝟮𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 🎯 Solved Continuous Subarray Sum using Prefix Sum & HashMap. ➤ Approach (O(n), O(n) space): — Maintain a running totalSum — Compute remainder = totalSum % k — Store the first index where each remainder appears — If the same remainder appears again and the distance between indices ≥ 2, a valid subarray exists ➤ Key Insight: If two prefix sums have the same remainder when divided by k, their difference is a multiple of k. #LeetCode #Java #DSA #PrefixSum #HashMap #ProblemSolving #20DaysChallenge #Consistency

  • text

To view or add a comment, sign in

Explore content categories