4

Split Array Into K Subarrays

Difficulty: EASY
Contributed By
Omkar Deshmukh
Avg. time to solve
25 min
Success Rate
75%

Problem Statement

You have given an integer array ‘arr’ size ‘N’. You have to split the array into ‘K’ consecutive non-overlapping subarrays of length ‘M’ such that every subarray contains a single distinct element.

You are required to check if it is possible to split the array with the above condition and print the answer in the binary format 1 if it is possible or 0 if it is not possible to split the array.

For Example:
Input:
N = 4 
M = 1 
K = 3
A[] = {5, 4, 1, 1}

Output 
1

The given array can be split like this [5], [4], [1] there are three consecutive non-overlapping subarrays. 
Input Format:
The first line contains a single integer 'T' denoting the number of test cases to be run. Then the test cases follow.

The first line of each test case contains three space-separated integers ‘N’, ‘M’, and ‘K’, where  ‘N’ denotes the size of the array, ‘M’ denotes the size of subarray required and ‘K’ denotes the number of subarrays required.

The second line of each test case contains ‘N’ space - separated 
integers denoting the elements of the given array. 
Output Format:
For each test case, print an integer  0 or 1. 1 if it is possible to split the array or 0 if it is not possible.

Output for each test case will be printed in a separate line.
Note:
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
Constraints:
1 <= T <= 50
1 <= N, M, K <= 100000
1 <= A[i] <= 100000

Time Limit: 1 sec.
Sample Input 1:
2
6 1 3
6 1 3 3 3 3
6 2 3
3 5 3 5 3 1
Sample Output 1:
1
0
Explanation For Sample Output 1:
In test case 1:

Here for this test case for the given test cases K consecutive 
non-overlapping subarrays are {6}, {1}, {3}}. hence the answer is 
1.

In test case 2:

For this test case, there is no possible way to divide the array, 
So the answer is 0. 
Sample Input 2:
2
5 3 2
4 3 5 2 5
5 1 2
3 2 2 2 2 
Sample Output 2:
0
1
Reset Code
Full screen
copy-code
Console