Menu
Back to Explore Page
Given an array of N integers, you have to find if it is possible to partition the array with following rules:
Example 1:
Input:
N = 5
K = 2
M = 3
A[] = {8, 3, 9, 1, 2}
Output:
YES
Explanation:
We can partition the array into two
partitions: {8, 9} and {3, 1, 2} such that
all rules are satisfied.
Your Task:
You don't need to read input or print anything. Your task is to complete the function partitionArray() which takes the number of elements N, integer K, integer M and array A[ ] as input parameters and returns true if we can partition the array such that all rules are satisfied, else returns false.
Expected Time Complexity: O(N * Log(N))
Expected Auxiliary Space: O(N)
Constraints:
1 ≤ N ≤ 2*105
1 ≤ K ≤ N
1 ≤ M ≤ 109
1 ≤ A[i] ≤ 109