We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Sherlock and Squares
Sherlock and Squares
Sort by
recency
|
1541 Discussions
|
Please Login in order to post a comment
C++ O(1) solution:
int squareRoot(int number){ int result=0; int variable=1;
}
int squares(int a, int b) { int lower=squareRoot(a); int upper=squareRoot(b); if(lower*lower==a){ //if a is perfect square, then decrement lower--; }
}
Here are my c++ solutions, you can watch the explanation here : https://youtu.be/LtU0ItsvbMI
Solution 1 O(√n)
Solution 2 O(1)
c#
Explanation: this, in general, returns the amount of integers between two numbers (+1 for inclusive).
Ex: a=24, b=47 >> floor(7) - ceil(4.90) + 1 = 7-5+1 = 3
Ex: a=24, b=24 >> floor(4.90) - ceil(4.90) + 1 = 4-5+1 = 0
Python 3