Count subarrays with sum equals k
Company: Apple
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Given an integer array `nums` (may contain negative numbers and zeros) and an integer `k`, return the **number of contiguous subarrays** whose sum is **exactly** `k`.
### Requirements
- The subarray must be contiguous.
- Your algorithm should handle negative values correctly.
### Input / Output
- **Input:** `nums: int[]`, `k: int`
- **Output:** `count: int` (number of contiguous subarrays with sum `k`)
### Example
- `nums = [1, 2, 3], k = 3` → output `2` because subarrays `[1,2]` and `[3]` sum to 3.
Quick Answer: This question evaluates a candidate's competency in array algorithms and reasoning about contiguous subarray sums, including correct handling of negative and zero values.