Skip to content

Latest commit

 

History

History
63 lines (39 loc) · 987 Bytes

Between_Extremes.md

File metadata and controls

63 lines (39 loc) · 987 Bytes

CodeWars Python Solutions


Between Extremes

Given an array of numbers, return the difference between the largest and smallest values.

For example:

[23, 3, 19, 21, 16] should return 20 (i.e., 23 - 3).

[1, 434, 555, 34, 112] should return 554 (i.e., 555 - 1).

The array will contain a minimum of two elements. Input data range guarantees that max-min will cause no integer overflow.


Given Code

def between_extremes(numbers):
    #Your code goes here!
    pass

Solution 1

def between_extremes(numbers):
    return max(numbers) - min(numbers)

Solution 2

def between_extremes(numbers):
    max = None
    min = None
    for n in numbers:
        if max is None:
            max = n
            min = n
        elif n > max:
            max = n
        elif n < min:
            min = n
    return max - min

See on CodeWars.com