Find minimum possible size of array with given rules for removing elements - GeeksforGeeks
Find minimum possible size of array with given rules for removing elements
Given an array of numbers and a constant k, minimize size of array with following rules for removing elements.
- Exactly three elements can be removed at one go.
- The removed three elements must be adjacent in array, i.e., arr[i], arr[i+1], arr[i+2]. And the second element must be k greater than first and third element must be k greater than second, i.e., arr[i+1] – arr[i] = k and arr[i+2]-arr[i+1] = k.
Example:
Input: arr[] = {2, 3, 4, 5, 6, 4}, k = 1 Output: 0 We can actually remove all elements. First remove 4, 5, 6 => We get {2, 3, 4} Now remove 2, 3, 4 => We get empty array {} Input: arr[] = {2, 3, 4, 7, 6, 4}, k = 1 Output: 3 We can only remove 2 3 4
Read full article from Find minimum possible size of array with given rules for removing elements - GeeksforGeeks
No comments:
Post a Comment