Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Contiguous Subarray Multiple Check

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Contiguous Subarray Multiple Check. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Adobe Creative Cloud can validate contiguous groups of asset-operation values against a divisibility rule. Given an integer array nums and an integer target, return True if the array contains a good subarray, and False otherwise.

A good subarray must:

  1. Be contiguous and contain at least two elements.
  2. Have a sum that is a multiple of target.

When target == 0, interpret the rule as requiring the subarray sum to equal 0.

Formal Specification

Implement check_subarray_sum(nums, target).

  • Input: nums, a list of integers, and target, an integer.
  • Output: A boolean indicating whether at least one valid subarray exists.
  • The same array element may not be used more than once, and the selected elements must be contiguous.

Constraints

  • 2 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • When target is zero, a valid sum must equal zero.

Function Signature

def check_subarray_sum(nums, target):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output