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
- 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
space-separated integers A1,A2,…,AN
For each test case, print a single line containing one integer ― the maximum sum of digits.
for each valid i
Subtask #1 (100 points): original constraints
3 2 2 8 3 8 2 8 3 9 10 11
7 10 18
My Code is as follows …
Please suggest optimization in THE algorithm of my code.
i = ( low-1 )
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 )
if low < high:
pi = partition(arr,low,high) quickSort(arr, low, pi-1) quickSort(arr, pi+1, high)
for i in range(1,T+1):
for k in range(len(A)):
for j in range(z,len(A)):
Problem Code —>RPD
and Problem Name---->Easy Math