C++ solution with linked article on geeksforgeeks for better understanding


credits to geeksforgeeks for this article. Read it for better understanding.

#define MAX 500
int multiply(int x, int fact[], int sz) {
    int carry=0;
    for(int i=0; i<sz; i++) {
        int prod=fact[i]*x+carry;
        fact[i] = prod%10;
        carry = prod/10;
    while(carry)    {
        fact[sz] = carry%10;
    return sz;

string Solution::solve(int A) {
    int fact[MAX];
    fact[0] = 1;
    int sz = 1;
    for(int x=2; x<=A; x++) sz = multiply(x, fact, sz);
    string ans="";
    for(int i=sz-1; i>=0; i--)  ans+=to_string(fact[i]);
    return ans;


It is crazy that this got accepted:

class Solution:
# @param A : integer
# @return a strings
def solve(self, A):
while A>=1:
b = b*(A)
A = A - 1
return b


Please explain the time complexity of this approach.