Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5646
@Quandray 5233
@akhayrutdinov 5111
@saiujwal13083 4716
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Minimum number of elements
Hard Accuracy: 48.18% Submissions: 106 Points: 8

Given an array arr of size N, the task is to make strictly increasing and strictly decreasing subsequences from the array such that each array element belongs to increasing subsequence or decreasing subsequence, but not both, or can be part of none of the subsequence. Minimize the number of elements that are not part of any of the subsequences and find the count of such elements.

Example 1:

Input: N = 12, arr[] = {7, 8, 1, 2, 4,
6, 3, 5, 2, 1, 8, 7}
Output: 2
Explanation:
Increasing sequence can be :
{1, 2, 4, 5, 8}.
Decreasing sequence can be :
{7, 6, 3, 2, 1}.
So, only 2 (8, 7) elements are left
which are not part of either of
the subsequences.
Example 2:
Input: N = 7, arr[] = {1, 4, 2, 3,
3, 2, 4}
Output: 0
Explanation:
Increasing sequence can be :
{1, 2, 3, 4}.
Decreasing sequence can be :
{4, 3, 2}.

You don't need to read input or print anything. Complete the function minCount() which takes N and array arr as input parameters and returns the integer value

Expected Time Complexity: O(N3)
Expected Auxiliary Space: O(N3)

Constraints:
1 ≤ N ≤ 102