Count Squares Geeks For Geeks

TIME O(sqrt(N)) [GFG time 0.4/1.4]

SPACE O(1)


Here we will be traversing till the square root of number and see weather i*i is more than or equal to n.

 class Solution {

    static int countSquares(int n) {

        

int a=0;

int count=0;

for(int i=1;i<Math.sqrt(n);i++){

a=i*i;

if(a<n){

count++;

}

}

       //System.out.println(count);

        return count;

        

        // code here

    }

};


Thanks for Reading.


Comments

Post a Comment

Popular posts from this blog

Solutions Of Practice Questions Dated 01-06-2022

CODEFORCES SPY DETECTED ROUND 713

Maximum Winning Score Geeks For Geeks