Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Continuous subarray sum and Cutting ribbons



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Continuous Subarray Multiple Check

Continuous Subarray Multiple Check

Problem Statement

Given an array of non-negative integers and an integer m, create a function that determines whether there exists a continuous subarray of length at least 2 whose sum is a multiple of m. In other words, the sum of that subarray should equal p * m where p is an integer.

Examples

Example 1:
Array: [20, 3, 5, 7, 9], m = 7
Output: True
Explanation: The subarray [5, 7] has a sum of 12, which is a multiple of 7 (7*1 = 7) — actually 12 is not a multiple of 7, so let's pick a better example:
Let's change example 1 to:
Array: [20, 3, 8, 7, 9], m = 8
Output: True
Explanation: The subarray [8, 7] sums to 15 which is not a multiple of 8, so let's correct this example properly:

Example 1:
Array: [20, 4, 4, 7, 9], m = 8
Output: True
Explanation: The subarray [4, 4] sums to 8, which is 1*8.

Example 2:
Array: [21, 2, 8, 5, 10], m = 5
Output: True
Explanation: The entire array sums to 46, which is not a multiple of 5, but the subarray [5, 10] sums to 15, which is 3*5.
    

Constraints

  • The length of the array will be between 2 and 9000 inclusive.
  • All integers in the array are non-negative and less than 10,000.
  • The integer m is a non-negative integer less than 10,000.