DIY: Continuous Subarray Sum

Solve the interview question "Continuous Subarray Sum" yourself in this lesson.

We'll cover the following

Problem statement

For this coding exercise, you are given an array of non-negative integers and an integer value k. Your task is to implement a function that checks if the array has a continuous subarray of a size at least 2 that sums up to a multiple of k. This means that the sum will be n * k where n is also an integer.

Input

The function will have two inputs: an integer array called numbers and a value called k, where k >= 1. The following is an example of the inputs:

numbers = [5, 2, 4, 6, 7]
k = 6

Output

The output will be true if the array has a continuous subarray of size at least 2 that sums up to a multiple of k. Otherwise, the output will be false. The output for the above-mentioned inputs will be:

true

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.