'''
For a given array, count the number of missing elements required
to make the array consecutive 

Example = [4,2,3,8]
Output = solution(a) = 3

'''

def solution(a):
    return max(a) - min(a) - len(a) + 1

print(
    solution([4,2,3,8])
) #output 3

print(
    solution([6,3])
) #output 2

print(
    solution([1])
) #output 0

print(
    solution([7,8,9])
) #output 0

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: