Question is
Chef is attending math classes. On each day, the teacher gives him homework. Yesterday, the teacher gave Chef a sequence of positive integers and asked him to find the maximum product of two different elements of this sequence. This homework was easy for Chef, since he knew that he should select the biggest two numbers.
However, today, the homework is a little bit different. Again, Chef has a sequence of positive integers A1,A2,…,AN
, but he should find two different elements of this sequence such that the sum of digits (in base 10
) of their product is maximum possible.
Chef thought, mistakenly, that he can still select the two largest elements and compute the sum of digits of their product. Show him that he is wrong by finding the correct answer ― the maximum possible sum of digits of a product of two different elements of the sequence A
.
Input
 The first line of the input contains a single integer T
denoting the number of test cases. The description of T* test cases follows.

The first line of the input contains a single integer N

.

The second line contains N
spaceseparated integers A1,A2,…,AN 
.
Output
For each test case, print a single line containing one integer ― the maximum sum of digits.
Constraints

1≤T≤100

2≤N≤100

1≤Ai≤104
for each valid i
Subtasks
Subtask #1 (100 points): original constraints
Example Input
3
2
2 8
3
8 2 8
3
9 10 11
Example Output
7
10
18
My Code is as follows …
Please suggest optimization in THE algorithm of my code.
def partition(arr,low,high):
i = ( low1 )
pivot = arr[high]
for j in range(low , high):
if arr[j] <= pivot:
i = i+1
arr[i],arr[j] = arr[j],arr[i]
arr[i+1],arr[high] = arr[high],arr[i+1]
return ( i+1 )
def quickSort(arr,low,high):
if low < high:
pi = partition(arr,low,high)
quickSort(arr, low, pi1)
quickSort(arr, pi+1, high)
T=int(input())
for i in range(1,T+1):
cf=[]
N=int(input())
A=list(map(int,input().split()))
if(len(A)==N):
for k in range(len(A)):
z=k+1
for j in range(z,len(A)):
p=A[k]*A[j]
m=p
s=0
while(m!=0):
d=m%10
s=s+d
m=m//10
cf.append(s)
quickSort(cf,0,len(cf)1)
print(cf[1])
Problem Code —>RPD
and Problem Name>Easy Math