I am trying to solve the following problem, but I'm stuck. The problem is as follows -
Suppose you have been given an array of integers. You have to remove some elements from the array so that the entire array can be sorted in ascending order. Elements can not be repeated, so if any element is repeated in the array, then it should also be removed.
I am posting some test cases so that the question becomes clear:
-
input
1 1 2
> -
Input - 1 7 8 9 3
Output - 1 (only 3 should be removed)
My approach to Had to go through the southern and if larger than the current number in the last number, it should be removed from the previous number. From this perspective, 1 and 2 will be resolved, but in this case 3 will have 3 outputs for this approach.
How should I solve this problem? Can a specific algorithm be helpful?
4 5
The array has been sorted since the output -2 (removed from 9.9 and it is also the minimum required number)
Suppose we have thrown some numbers so that the remaining array To be sorted. What is the remaining number in the initial array? Increasing Growth We want to throw as many numbers as we can, or keep it in another way, keep the number as much as possible. In this way, we need to find the longest growing variations in the given array.
No comments:
Post a Comment