The problem that i am facing with the below question is that big test cases take more that 5 seconds and also the fact that large numbers that are above 10^9+7 causes it to give me a wrong answer.
Determine the maximum subsequence product that can be formed from the elements of this array. Moreover, any pair of index i and index j is present in the same subsequence if and only if their product i*j is a perfect square.Since the answer can be large, output the answer modulo .
You are given an array as an input (1 dimensional) we will use 1 based indexing (start count from 1 instead of 0). now what you have to find is find
all pairs of (i,j) where i*j is a perfect square and multiply the values at i and j together now try the same with a different
i find the
i that gives you the maximum product and return the maximum product
N = 8 (size of the array)
A = 8 7 6 5 4 3 2 9 (The array)
I approached this in a brute force method like a two pointer problem.
taking a left pointer and then a right pointer as the last index of the list and checking whether they from a perfect square when multiplied and continuing to multiply values of other indexes until all values inside the array with the same L index is multiplied together and finaly check if that is the maximum value that can be obtained.