Coding
Published on

Codesignal - Make Array Consecutive 2 solution

Authors

Solution one:

def makeArrayConsecutive2(statues):
    return max(statues) - min(statues) - len(statues) + 1

Solution two:

def makeArrayConsecutive2(statues):
    list.sort(statues)
    return statues[-1] - statues[0] + 1 - len(statues)

Solution three:

def makeArrayConsecutive2(statues):
    return sum([1 for i in range(min(statues), max(statues)) if i not in statues])

Solution four:

def makeArrayConsecutive2(statues):
    lowest = min(statues)
    highest = max(statues)+1
    completeList = list(range(lowest, highest))

    for i in statues:
        if i in completeList:
            completeList.remove(i)

    return len(completeList)