← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026Remote

Summary

Meta SWE coding round, one question the whole time: subarray sum equals k. Seemed straightforward at first but the negative numbers constraint is what separates the brute force people from everyone else.

Questions Asked (1)

Q1

Given an integer array and a target value k, count the number of contiguous subarrays whose elements sum to k. The array can contain negative numbers.

Algorithms & Data Structures
Author's notes

My first instinct was the sliding window approach and I started explaining it before realizing negative numbers completely break that.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then propose a brute-force solution and optimize it using a hash map to track prefix sums. Explain how the hash map stores the frequency of each prefix sum and how to compute the count in O(n) time.

Pro tip: Mention that the hash map approach handles negative numbers seamlessly because it relies on prefix sums, not sliding window. Also, initialize the map with {0:1} to account for subarrays starting at index 0.

1. Clarify the problem

Ask about input constraints, expected output, and edge cases such as empty array or k=0. Confirm that subarrays must be contiguous and that negative numbers are allowed.

2. Discuss brute-force approach

Mention that a naive solution checks all O(n^2) subarrays and sums them, which is inefficient. This shows you understand the baseline.

3. Introduce prefix sum optimization

Explain that the sum of a subarray from i to j is prefixSum[j] - prefixSum[i-1]. So, for each j, we need to count how many i have prefixSum[i-1] = prefixSum[j] - k.

4. Use hash map for O(n) solution

Iterate through the array, maintaining a running sum and a hash map that maps prefix sum to its frequency. For each element, add the frequency of (currentSum - k) to the count, then update the map with currentSum.

5. Analyze complexity and edge cases

State that time complexity is O(n) and space is O(n). Discuss handling of negative numbers and initialization of the map with {0:1}.

Key Points to Mention

  • Prefix sum concept and its role in subarray sum problems
  • Hash map to store frequency of prefix sums
  • Initialization of hash map with {0:1} to handle subarrays starting at index 0
  • Time and space complexity analysis (O(n) time, O(n) space)
  • Handling negative numbers and why sliding window doesn't work
  • Edge cases: empty array, k=0, large input

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.