#K95312. Check Subarray Sum
Check Subarray Sum
Check Subarray Sum
You are given an integer array nums
and an integer k
. Your task is to determine if the array has a continuous subarray of size at least 2 whose elements sum up to a multiple of k. In other words, check whether there exists a subarray of at least two elements such that its sum is of the form $$m \times k,$$ where \( m \in \mathbb{Z} \).
Note that when k = 0
, a valid subarray is one where the sum is exactly 0, and in particular, the presence of consecutive zeros constitutes a valid solution. Your solution should read input from stdin and write the answer to stdout as either True
or False
.
inputFormat
The input consists of three lines:
- An integer
n
representing the number of elements in the array. n
space-separated integers which represent the arraynums
.- An integer
k
.
outputFormat
Output a single line with either True
or False
depending on whether there exists a continuous subarray of size at least 2 whose sum is a multiple of k
.
5
23 2 4 6 7
6
True