Uber | Online Assessment
Anonymous User
959

Convert an array into strictly increasing or decreasing where each number differ by 1. You can only add the numbers to array element but not reduce it. Find the minimum number of inserting you have to do on array elements for making it either consecutive ascending or descending.

Eg, array: [3,7,6,4], => min insertion: 6.

Solution: This array can be converted into consecutive descending order - [8,7,6,5].
For converting from original array to this, we need to add 5 in array[0] and 1 in array[3].

Comments (5)