Sort by

recency

|

1147 Discussions

|

  • + 0 comments
    def factorial(n):
        # Write your code here
        if n==0 or n==1:
            return 1
        else:
            return n*factorial(n-1)
    
  • + 2 comments

    run code was successful.But hidden test cases are failure.why?? anyboidy please explain to my problem

  • + 0 comments

    My solution with JavaScript:

    // Base case at 2 to avoid redundancy: multiplying by 1 does not change the result.
    function factorial(n) {
        if(n > 2) {
            return n * factorial(n-1);
        } else {
            return 2;
        }
    }
    
  • + 0 comments

    Java 15

    I tried to use BigInteger instead of int, and I got an error because BigInteger doesn't overflow. I checked the constraints, which allow numbers between two and twelve. If someone uses twelve with int in this exercise, an overflow will occur. It would be better to explain this in the exercise or reduce the constraints to eleven.

  • + 0 comments

    return (math.factorial(n))