feat: find_missing
This commit is contained in:
@@ -9,3 +9,14 @@ def maximum_subarray_sum(input_array: list[int]):
|
|||||||
max_sum = temp_sum
|
max_sum = temp_sum
|
||||||
subarray = temp_subarray
|
subarray = temp_subarray
|
||||||
return [max_sum, subarray]
|
return [max_sum, subarray]
|
||||||
|
|
||||||
|
def get_array_range(min, max):
|
||||||
|
arr = []
|
||||||
|
for n in range(min, max + 1):
|
||||||
|
arr.append(n)
|
||||||
|
return arr
|
||||||
|
|
||||||
|
def find_missing(input_aray: list[int]):
|
||||||
|
return sum(get_array_range(1, len(input_aray) + 1)) - sum(input_aray)
|
||||||
|
|
||||||
|
def trap_rain_water(input_aray: list[int]):
|
||||||
|
|||||||
@@ -16,4 +16,12 @@ def test_subarray_sum():
|
|||||||
expected = [25, [5,4,1,7,8]]
|
expected = [25, [5,4,1,7,8]]
|
||||||
assert result == expected
|
assert result == expected
|
||||||
|
|
||||||
|
def test_find_missing():
|
||||||
|
input = [8,2,4,5,3,7,1]
|
||||||
|
result = find_missing(input)
|
||||||
|
expected = 6
|
||||||
|
assert result == expected
|
||||||
|
input = [1,2,3,5]
|
||||||
|
result = find_missing(input)
|
||||||
|
expected = 4
|
||||||
|
assert result == expected
|
||||||
|
|||||||
Reference in New Issue
Block a user