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.
// a: an integer, the lower range boundary// b: an integer, the upper range boundaryintsquares(inta,intb){// floor(sqrt(b)) - sqrt of perfect square within upper limit// ceil(sqrt(a)) - square root of perfect square above lower limit// +1 - to make the range inclusivereturnfloor(sqrt(b))-ceil(sqrt(a))+1;}
2. Python 3 One liner: with inline comments
defsquares(a,b):# math.floor(math.sqrt(b)) - sqrt of perfect square within upper limit# math.ceil(math.sqrt(a)) - square root of perfect square above lower limit# +1 - to make the range inclusivereturnmath.floor(math.sqrt(b))-math.ceil(math.sqrt(a))+1
Feel free to ask your questions or concerns - by Danie
Cookie support is required to access HackerRank
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 →
O(1) Solutions
1. C One liner: with inline comments
2. Python 3 One liner: with inline comments
Feel free to ask your questions or concerns - by Danie