FastPrepContinuous Subarray Sum Multiple
Problems/Continuous Subarray Sum Multiple

Continuous Subarray Sum Multiple

Microsoft logoMicrosoft● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft onsite interview. The report only names the task by sound, and we read it as a well-known problem. Its public statement gives the examples and the limits. Our version is about 95% the same as the reported question.

Given an integer array nums and a positive integer k, return true if some contiguous subarray contains at least two elements and its sum is an integer multiple of k. Return false otherwise.

A subarray uses consecutive positions from nums. A sum s is a multiple when s = m * k for some integer m. Zero is a multiple of every positive k, so a zero-sum range can qualify.

Function

checkSubarraySum(nums: int[], k: int) → boolean

Examples

Example 1

nums = [23,2,4,6,7]k = 6return = true

The adjacent values 2 and 4 sum to 6, so this two-element subarray qualifies.

Example 2

nums = [23,2,6,4,7]k = 6return = true

The whole array has five elements and sums to 42 = 7 * 6, so it qualifies.

Example 3

nums = [23,2,6,4,7]k = 13return = false

No contiguous subarray with at least two elements has a sum that is a multiple of 13.

Constraints

  • 1 <= nums.length <= 10^5.
  • 0 <= nums[i] <= 10^9.
  • 0 <= sum(nums) <= 2147483647.
  • 1 <= k <= 2147483647.

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Subarray Sum Equals KServiceNow · ONSITE INTERVIEWServiceNow interview questions
  • Maximum Subarray Sum with Equal EndpointsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Count Subarrays with Sum KMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
  • Subarray Sum Equals KApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • Longest Equal-Zero-One SubarrayMotive · PHONE SCREEN · ONSITE INTERVIEWMotive interview questions
  • Find and Measure the Longest Target-Sum SubarrayMeta · ONSITE INTERVIEWMeta interview questions
  • Longest Subarray with a Target SumPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
  • Count Subarrays Whose Sum Is KExpedia · ONSITE INTERVIEWExpedia interview questions
  • Number of Submatrices That Sum to TargetWhatNot · ONSITE INTERVIEWWhatNot interview questions
  • Maximum Sum Desirable SubarrayGroww · PHONE SCREEN

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public boolean checkSubarraySum(int[] nums, int k) {
        // write your code here
    }
}
Checking account…