Delete array elements which are smaller than next or become smaller
Easy Accuracy: 27.75% Submissions: 5584 Points: 2
Given an array arr and a number k. The task is to delete k elements which are smaller than next element (i.e., we delete arr[i] if arr[i] < arr[i+1]) or become smaller than next because next element is deleted.
The first line contains an integer T, the number of test cases. For each test case, the first line contains an integer n, denoting the size of the array. Next line contains n space separated integers, followed by an integer k, denoting the number of elements to be deleted from the array.
For each test case, the output is the array arr after deleting the k elements from the array if possible, else print the left array as it is.
1. arr < arr means 3 is less than 100, so delete 3. 2. First we delete 10 because it follows arr[i] < arr[i+1]. Then we delete 20 because 25 is moved next to it and it also starts following the condition. 3. We delete 23, 45 and 11 as they follow the condition arr[i] < arr[i+1]. 4. As after deleting 2, we are left with 5 only and hence 5 is the answer.