← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

Phone screen for a senior SWE role at Meta, two coding problems back to back. The second one was this prefix-sum modulo thing that looks easy until you start handling edge cases and suddenly you're explaining language-specific modulo behavior to a skeptical interviewer.

Questions Asked (1)

Q1

Given an integer array and an integer k, determine whether there exists a contiguous subarray of length at least 2 whose sum is a multiple of k.

Algorithms & Data Structures
Author's notes

The core trick is prefix sums mod k, store the first time you see each remainder and check if you've seen it before with enough distance between indices.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use prefix sums and modular arithmetic: compute prefix sums modulo k and check if any remainder repeats within a distance of at least 2. If a remainder repeats, the subarray between those indices has a sum divisible by k; ensure its length is at least 2 by tracking the earliest index for each remainder.

Pro tip: Handle edge cases explicitly: k=0 (though typically k>0), negative numbers (modulo operation in some languages returns negative), and the length constraint. Also, mention that the solution runs in O(n) time and O(k) space, which is optimal.

1. Clarify problem and constraints

Confirm that k is positive, array can contain negative numbers, and subarray must be contiguous with length >= 2. Ask about expected input size to determine if O(n) is necessary.

2. Explain prefix sum and modulo property

State that if two prefix sums have the same remainder modulo k, the sum of the elements between them is a multiple of k. This is because (prefix[j] - prefix[i]) % k == 0.

3. Design algorithm with earliest index tracking

Iterate through the array, compute running sum modulo k, and store the first index where each remainder occurs. If a remainder repeats and the distance between indices is at least 2, return true.

4. Handle edge cases and negative remainders

Ensure modulo results are non-negative (e.g., in Python use % k, in Java use Math.floorMod). Also, initialize the map with remainder 0 at index -1 to handle subarrays starting from index 0.

5. Analyze complexity and test

State time complexity O(n) and space O(min(n, k)). Walk through a small example to verify, including cases with negative numbers and no valid subarray.

Key Points to Mention

  • Prefix sum modulo k property: equal remainders imply subarray sum divisible by k.
  • Length constraint: need at least 2 elements, so track earliest index and check distance >= 2.
  • Handling negative numbers: ensure modulo operation yields non-negative remainder.
  • Initialization: include remainder 0 at index -1 to account for subarrays starting at index 0.
  • Time and space complexity: O(n) time, O(min(n, k)) space.
  • Edge cases: k=1 (always true if length >=2), empty array, array length < 2.

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