Permute the Array
Practice
3.1 (27 votes)
Arrays
Data structures
Easy
Hash maps
Implementation
One Dimensional
Problem
41% Success 5941 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array consisting of $$N$$ integers. You need to determine whether any permutation of given array exist such that the sum of all subarrays of length $$K$$ are equal.
Input format :
- The first line consist of $$T$$ denoting the number of testcases.
- The first line of each testcase consist of two space seperated integers $$N$$ and $$K$$.
- The second line of each testcase consist of $$N$$ space seperated integers denoting array elements.
Output format :
- Print "YES" or "NO" for each testcase in a new line.
Constraints :
- \(1 \le T \le 10 \)
- \(1 \le K \le N \le 10^{6}\)
- \(1 \le A_{i} \le 10^{5}\)
- $$N$$ is divisible by $$K$$ i.e \(N\mod K=0\)
Explanation
In the first test case there is no permutation for which the array satisifes the conditon.
In the second test since whole array is a subarray of length 5 so the answer is YES.
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
16 votes
Tags:
HardFlowGreedy algorithm
Points:20
63 votes
Tags:
Arrays1-DData Structures
Points:20
280 votes
Tags:
ApprovedData StructuresEasyOpenQueue
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output