I was reading an interview experience of Uber and came across this question which was asked in OA. Any hints/guesses how to solve this...

Given an array A of N elements, you can perform the following operation any number of times(possibly 0).
You can replace any integer of the array with an integer.
Your task is to print the minimum operations required to make the elements continuous.

Constraints: 1 <= N <= 1e6, 1 <= A[i] <= 1e9

Example:
Input: 4 7 11 6 9
Output: 2
Explaination: 
We can replace 11 with 5 and 9 with 8, 
resulting in the array [4, 7, 8, 6, 5]
which contains all the elements from 4 to 8.
Comments (12)