Whats wrong in this simple querie

whats wrong in this simple querie

public class Solution {
public int[] solve(int[] A, int[] B) {
ArrayList G=new ArrayList();
for(int i=0;i<A.length;i++)
{
for(int j=i;j<A.length;j++)
{
int max=A[i];
for(int k=i+1;k<=j;k++)
{
if(max<A[k])
max=A[k];
}
G.add(max);
}
}
long prodOfDivisor;
for(int i=0;i<G.size();i++)
{
prodOfDivisor=1L;
for(int j=2;j<=G.get(i);j++)
{
if(G.get(i)%j==0)
prodOfDivisor*=j;
}
G.set(i,(int)(prodOfDivisor%1000000007));
}
Collections.sort(G);
for(int i=0;i<B.length;i++)
{
B[i]=G.get(G.size()-B[i]);
}
return B;
}
}

Comment body goes here.
What is wrong with my code:

public class Solution {

public int findProdOfDivisors(int num)
{
    int m = 1000000007;
    ArrayList<Integer> ar= new ArrayList<Integer>();
    for(int i=1;i<=Math.sqrt(num);i++)
    {
        if(num%i==0)
        {
            if(num/i == i)
                ar.add(i);
            else
            {
                ar.add(i);
                ar.add(num/i);
            }
        }
    }
    int prod=1;
    for(int i=0;i<ar.size();i++)
    {
      prod*=ar.get(i); 
      if(prod>m)
        prod=prod%m;
    }
    return prod%m;
    
}
public ArrayList<Integer> solve(ArrayList<Integer> A, ArrayList<Integer> B) {
    ArrayList<Integer> G= new ArrayList<Integer>();
    for(int i=0;i<A.size();i++)
    {
        for(int j=i+1;j<=A.size();j++)
        {
            G.add(findProdOfDivisors(Collections.max(A.subList(i,j))));
        }
    }
    Collections.sort(G, Collections.reverseOrder());
    ArrayList<Integer> ans= new ArrayList<Integer>();
    for(int i=0;i<B.size();i++)
    {
        ans.add(G.get(B.get(i)-1));   
    }
    return ans;
}

}

I dont know who writes solutions to these problems. But whoever that guy is, surely knows to screw with us all

instead of using mod at the end, use it while multiplying
something like

prod = (prod * j) % 1000000007.

and later add to the array

If lucky, you might get “Time Limit Exceeded”. If you are “the one”, you will get the 1379th person to get it correct

Click here to start solving coding interview questions