You are viewing a single comment's thread. Return to all 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; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Squares
You are viewing a single comment's thread. Return to all comments →
Here are my c++ solutions, you can watch the explanation here : https://youtu.be/LtU0ItsvbMI
Solution 1 O(√n)
Solution 2 O(1)