Short and simple answer in Python but getting TLE


#1

class Solution:
# @param A : list of integers
# @param B : list of integers
# @return a list of integers
def prod_divisors(self, n):
prod = 1
# count = 0
for i in range(1, int(n**0.5)+1):
if n%i == 0:
if i == n//i:
prod *= i
# count += 1
else:
# count += 2
prod *= i
prod *= n//i

            prod = prod % (10**9 + 7)
            
    return prod % (10**9 + 7)
    # return int(n**(count/2)) % (10**9 + 7)

def solve(self, A, B):
    prod_of_divisors = {}
    for a in A:
        prod_of_divisors[str(a)] = self.prod_divisors(a)
    
    
    max_subArrays = []
    for i in range(len(A)):
        for j in range(i, len(A)):
            max_subArrays.append(prod_of_divisors[str(max(A[i:j+1]))])
    
    max_subArrays.sort(reverse=True)
    
    # A.sort()
    # max_subArrays = []
    # for i in range(len(A)-1, -1, -1):
    #     l = [prod_of_divisors[str(A[i])]] * (i+1)
    #     max_subArrays += l
    
    ans = []
    for b in B:
        ans.append(max_subArrays[b-1])
        
        
    return ans