arr containing n elements.i such that 1 <= i < n.left = arr[0:i] and right = arr[i:n].countDistinct(left) + countDistinct(right) among all permitted split positions.Implement the following function:
def maxSum(arr):
Input: arr = [1, 2, 1, 3]
Output: 4
Splitting after the first element gives 1 + 3 = 4, and splitting after the second gives 2 + 2 = 4; no split produces a larger sum.
Input: arr = [6, 6, 6, 6]
Output: 2
Every non-empty side contains exactly one distinct value, so every valid split has a total of 1 + 1 = 2.
Input: arr = [4, 9, 2, 7, 1]
Output: 5
All values are different, so a split after any position contributes the number of elements on the left plus the number on the right, totaling 5.
arr contains integers.