← All mock interviewsHints used: 0
Subarray Sum Equals K Mock Interview
- ✓Problem→
- 2Clarifying Questions→
- 3Constraints→
- 4Brute Force→
- 5Complexity Analysis→
- 6Pattern Recognition→
- 7Optimized Solution→
- 8Implementation→
- 9Testing→
- 10Follow-Up→
- 11Evaluation
Problem
Given an array of integers nums (which may include negatives and zeros) and an integer k, return the total number of contiguous subarrays whose sum equals exactly k. Subarrays are counted by position, so identical values at different positions count separately.
Constraints
- 1 ≤ n ≤ 2·10^4
- -1000 ≤ nums[i] ≤ 1000
- -10^7 ≤ k ≤ 10^7
Example
in: nums = [1,1,1], k = 2
out: 2
Clarify
Before choosing anything: what would you ask the interviewer? What assumptions are you making? (Duplicates? Empty input? Value ranges? What to return when there is no answer?)