r/leetcode • u/JacketFearless1805 • 10h ago
Intervew Prep Day 17: worked through Largest Subarray with 0 Sum & Count Subarrays with Given XOR
Hey everyone,
I finished Day 17 today. Honestly, I was not really in the mood to study, so I leaned on video explanations to get through two problems, and I am glad I stuck with it:
- Largest Subarray with 0 Sum: Track the running prefix sum and store the first index where each sum appears in a hash map. If the same prefix sum shows up again at index
i, the subarray between the first occurrence andisums to zero. - Count Subarrays with Given XOR: Similar prefix approach, except with bitwise XOR. Maintain the running prefix XOR and check how many times
prefixXOR ^ targethas already appeared in the map to count all valid subarrays ending at the current index.
The biggest takeaway for me today was seeing how clearly subsequence and subarray problems separate:
- Subsequences usually point toward recursion or DP (take / not-take).
- Subarrays almost always come down to Kadane's algorithm, a sliding window, or prefix sums/XOR with a hash map.
Back in college, seeing "subsequence" or "subarray" in a prompt used to throw me off right away. Now, at least I have a clear mental framework for how to approach them instead of getting overwhelmed.
See you guys tomorrow for Day 16!
2
Upvotes