Maximum Tip Calculator | Function that finds the maximum tips from the given arrays as per the given conditions ; Base Condition ; If both have non - zero count then return max element from both array ; Traverse first array , as y count has become 0 ; Traverse 2 nd array , as x count has become 0 ; Drive Code ; Function Call
def maximumTip ( arr1 , arr2 , n , x , y ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT if x != 0 and y != 0 : NEW_LINE INDENT return max ( arr1 [ n - 1 ] + maximumTip ( arr1 , arr2 , n - 1 , x - 1 , y ) , arr2 [ n - 1 ] + maximumTip ( arr1 , arr2 , n - 1 , x , y - 1 ) ) NEW_LINE DEDENT if y == 0 : NEW_LINE INDENT return arr1 [ n - 1 ] + maximumTip ( arr1 , arr2 , n - 1 , x - 1 , y ) NEW_LINE DEDENT else : NEW_LINE INDENT return arr2 [ n - 1 ] + maximumTip ( arr1 , arr2 , n - 1 , x , y - 1 ) NEW_LINE DEDENT DEDENT N = 5 NEW_LINE X = 3 NEW_LINE Y = 3 NEW_LINE A = [ 1 , 2 , 3 , 4 , 5 ] NEW_LINE B = [ 5 , 4 , 3 , 2 , 1 ] NEW_LINE print ( maximumTip ( A , B , N , X , Y ) ) NEW_LINE