I have going for this approach acc to the hint but it was giving me errors so i decided to look for this code in geeksforgeeks but still gving me errors… please help
def getMinMax(self,low, high, arr):
arr_max = arr[low]
arr_min = arr[low]
# If there is only one element
if low == high:
arr_max = arr[low]
arr_min = arr[low]
return (arr_max, arr_min)
# If there is only two element
elif high == low + 1:
if arr[low] > arr[high]:
arr_max = arr[low]
arr_min = arr[high]
else:
arr_max = arr[high]
arr_min = arr[low]
return (arr_max, arr_min)
else:
# If there are more than 2 elements
mid = int((low + high) / 2)
arr_max1, arr_min1 = self.getMinMax(low, mid, arr)
arr_max2, arr_min2 = self.getMinMax(mid + 1, high, arr)
return (max(arr_max1, arr_max2), min(arr_min1, arr_min2))