In: Computer Science
Python:
Write a function that receives a one dimensional array of integers and returns a Python tuple with two values - minimum and maximum values in the input array. You may assume that the input array will contain only integers and will have at least one element. You do not need to check for those conditions.
Restrictions: No built-in Python data structures are allowed (lists, dictionaries etc). OK to use a Python tuple to store and return the result.
Below is the starter skeleton code for this problem, on which the implementation must be built. Methods defined in the skeleton code must retain their names and input / output parameters. Variables defined in skeleton code must also retain their names.
from a1_include import
*def min_max(arr: StaticArray) -> ():
"""
TODO: Write this implementation
"""
return 0, 0
# BASIC TESTING
if __name__ == "__main__":
# example 1
arr = StaticArray(5)
for i, value in enumerate([8, 7, 6, -5, 4]):
arr[i] = value
print(min_max(arr))
# example 2
arr = StaticArray(1)
arr[0] = 100
print(min_max(arr))
# example 3
arr = StaticArray(3)
for i, value in enumerate([3, 3, 3]):
arr[i] = value
print(min_max(arr))
#!usr/bin/python
# from a1_include import StaticArray
def min_max(arr: StaticArray) -> ():
"""
TODO: Write this implementation
"""
mi = minimum(arr)
ma = maxmimum(arr)
return (mi, ma)
def minimum(arr: StaticArray) -> ():
mi = arr[0]
if len(arr) == 1:
return mi
else:
for i in
range(len(arr)):
if mi < arr[i]:
mi = arr[i]
return mi
def maximum(arr: StaticArray) -> ():
ma = arr[0]
if len(arr) == 1:
return ma
else:
for i in
range(len(arr)):
if ma > arr[i]:
ma = arr[i]
return ma
# BASIC TESTING
if name == "main":
# example 1
arr = StaticArray(5)
for i, value in enumerate([8, 7, 6, -5, 4]):
arr[i] = value
print(min_max(arr))
# example 2
arr = StaticArray(1)
arr[0] = 100
print(min_max(arr))
# example 3
arr = StaticArray(3)
for i, value in enumerate([3, 3, 3]):
arr[i] = value
print(min_max(arr))