← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Google SWE coding round, one problem, pretty standard prefix sum territory but I fumbled around longer than I should have.

Questions Asked (1)

Q1

Given an integer array and an integer k, determine whether the array contains a contiguous subarray of at least two elements whose sum is divisible by k.

Algorithms & Data Structures
Author's notes

Took me a minute to stop thinking brute force.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use prefix sums modulo k and a hash map to track the earliest index of each remainder. If a remainder repeats at indices i and j (i < j), the subarray between them has a sum divisible by k; ensure the subarray length is at least 2 by checking j - i >= 2.

Pro tip: Clarify edge cases upfront: k can be negative or zero (though typically k > 0), and the array may contain negative numbers. Mention that the modulo operation should handle negatives correctly (e.g., using ((sum % k) + k) % k).

1. Understand the problem

Restate the problem: find a contiguous subarray of length >= 2 whose sum is divisible by k. Confirm constraints and edge cases (e.g., k=0, negative numbers).

2. Use prefix sums modulo k

Compute prefix sums modulo k. If two prefix sums have the same remainder, the subarray between them has a sum divisible by k.

3. Track earliest index with hash map

Use a hash map to store the first index where each remainder occurs. Initialize with remainder 0 at index -1 to handle subarrays starting from the beginning.

4. Check for valid subarray length

When a remainder repeats, check if the distance between indices is at least 2. If yes, return true. Otherwise, continue.

5. Return result and analyze complexity

If no valid subarray found, return false. Time complexity O(n), space O(min(n, k)).

Key Points to Mention

  • Prefix sum modulo k and the pigeonhole principle
  • Handling negative numbers with proper modulo operation
  • Hash map to store earliest index of each remainder
  • Edge cases: k=0, k=1, array length < 2
  • Time and space complexity analysis
  • Why subarray length must be at least 2 (avoid single element divisible by k)

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