![]() |
VOOZH | about |
Given an array arr[] of size N. The task is to split the array into minimum number of strictly decreasing subsequences. Calculate the minimum number of subsequences we can get by splitting.
Examples:
Input: N = 4, arr[] = {3, 5, 1, 2}
Output: 2
Explanation: We can split the array into two subsequences: {3,1} and {5,2}Both are strictly decreasing subsequence.
Input: N = 3, arr[] = {3,3,3}
Output: 3
Explanation: We can split the array into three subsequences: {3},{3} and {3}
Approach: To solve the problem, follow the below idea:
If we observe carefully, we can see that the Minimum number of decreasing subsequences is equal to the length of longest increasing subsequence where each element from the longest increasing subsequence belongs to a single decreasing subsequence, so it can be found in N*Log(N).
Below is the implementation of the above approach:
Length of the minimum decreasing subsequence: 3
Time Complexity: O(N log N), where N is the length of array arr[].
Auxiliary Space: O(N)