Program to convert the positive array using either decrement or delete operation based on the cost involved for the operation.
1) Decrement -> cost = 1
2) Delete an element completely from the array -> cost = value of element
For example:
4,3,5,6, -> cost 1 //cost is 1 to make 4->3
10,3,11,12 -> cost 3 // cost 3 to remove 3
Following cases were tried and produced the expected result:
Input:
4 3 5 6
Output:
3 3 5 6
------------------
Input:
10 3 11 12
Output:
10 11 12
------------------
Input:
3 10 7 9 1
Output:
3 7 7 9
------------------
Input:
1 1 1 1000 1
Output:
1 1 1 1000
------------------
Input:
10 2 3
Output:
10
------------------
1) Decrement -> cost = 1
2) Delete an element completely from the array -> cost = value of element
For example:
4,3,5,6, -> cost 1 //cost is 1 to make 4->3
10,3,11,12 -> cost 3 // cost 3 to remove 3
Following cases were tried and produced the expected result:
Input:
4 3 5 6
Output:
3 3 5 6
------------------
Input:
10 3 11 12
Output:
10 11 12
------------------
Input:
3 10 7 9 1
Output:
3 7 7 9
------------------
Input:
1 1 1 1000 1
Output:
1 1 1 1000
------------------
Input:
10 2 3
Output:
10
------------------
No comments:
Post a Comment