ONLINE ASSESMENT | SDE1
Anonymous User
978

QUESTION:
Mike is the naughtiest student in the class. So, Bob, his class teacher, gave him a sequence A containing only 0 and 1.
Bob wanted Mike to divide the sequence in such a way that each division must give the sum exactly K.
To increase Mike's punishment, Bob wanted that Mike should find all the unique divisions that follow the given conditions.

Notes:
The count of divisions can be huge. So, Output the count mod 109+7.
The whole array is not considered as a division.

Determine all unique divisions such that each segment has a sum equal to exactly K. If there are no new divisions possible, return 0.

Example-1:
Given,
N = 18, K = 4
A = 0 1 1 1 1 0 1 0 1 1 0 1 0 1 1 1 1 0
Approach

1st division: 0 1 1 1 1 - 0 1 0 1 1 0 1 0 - 1 1 1 1 0
2nd division: 0 1 1 1 1 0 - 1 0 1 1 0 1 0 - 1 1 1 1 0
3rd division: 0 1 1 1 1 - 0 1 0 1 1 0 1 - 0 1 1 1 1 0
4th division: 0 1 1 1 1 0 - 1 0 1 1 0 1 - 0 1 1 1 1 0
Mike can form 4 diffrent sequences.
Example-2:
Given

N = 3
K = 1
A = 0 1 0
Approach

You cannot get any new divisions. Hence, print 0.

Comments (2)