Factorial Number Geeks For Geeks

Problem Link:

https://practice.geeksforgeeks.org/problems/factorial-number2446/1



Solution :

class Solution{

    static int isFactorial(int n) {

        //code here

        int val=1;

        int index=1;

        

       while(val<n){

           

           val=val*index;

           index++;

       }

       if(val==n){

           return 1;

       }

       else{

           return 0;

       }

        

    }

}


TIME:O(Log n)[Every Time multiplication with 2][GFG Time:0.2/1.4]

SPACE:O(1)

AUXILLARY SPACE:O(1)[Only Constants]

Total Test Cases:11555


Approach: 

We will apply the while loop and see whether the value(val) is less than a given number.(n)

The loop will break only when the value(val) is more or equal which we will check later.

If the value(val) is equal then yes the number is factorial and returns 1 else returns 0.



Thanks For Reading.😇

"Share Further To Increase Knowledge Treasure".😊


Comments

Popular posts from this blog

Solutions Of Practice Questions Dated 01-06-2022

CODEFORCES SPY DETECTED ROUND 713

Maximum Winning Score Geeks For Geeks