Question: Extra Long Factorials(https://www.hackerrank.com/challenges/extra-long-factorials/problem) constraints : 1<n<=100
I am doing in an efficient way plus its the same solution available in net still when I am submitting the code its showing TLE. Below is my code
public static void multiply(ArrayList<Integer> prod,int i)
{
int carry=0;
for(int j=0;j<prod.size();j++)
{
int currp=prod.get(j)*i+carry;
prod.add(j,currp%10);
carry=currp/10;
}
while(carry>0)
{
prod.add(carry%10);
carry/=10;
}
}
// Complete the extraLongFactorials function below.
static void extraLongFactorials(int n) {
ArrayList<Integer> prod= new ArrayList<>();
prod.add(1);
for(int i=2;i<n;i++)
multiply(prod,i);
for(int i=prod.size()-1;i>=0;i--)
System.out.print(prod.get(i));
System.out.println();
}