Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6420
@blackshadows 6380
@mb1973 5704
@Quandray 5245
@akhayrutdinov 5111
@saiujwal13083 5046
@sanjay05 3762
@kirtidee18 3673
@mantu_singh 3530
@marius_valentin_dragoi 3523
@sushant_a 3459
Complete Leaderboard
Minimum number of elements
Hard Accuracy: 55.63% Submissions: 126 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}.


Your Task:  
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

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Minimum number of elements

Output Window