• + 0 comments

    Here are my c++ solutions, you can watch the explanation here : https://youtu.be/LtU0ItsvbMI

    Solution 1 O(√n)

    int squares(int a, int b) {
        int i = ceil(sqrt(a)), result = 0;
        for(; i * i <= b; i++) result++;
        return result;
    }
    

    Solution 2 O(1)

    int squares(int a, int b) {
        int i = ceil(sqrt(a)), j = floor(sqrt(b));
        return j - i + 1;
    }