Hackerrank – Sherlock and Squares

Hackerrank – Problem Statement

A description of the problem can be found on Hackerrank.


We have to prevent timeout, because there is big upper constraint. For a given numbers a and b we can find out all square numbers with formula:

    \[\lfloor a \rfloor - \lceil b \rceil + 1\]


There is a special case when a and b are equals. Then you have to check if a or b is a square number.

I created solution in:

All solutions are also available on my GitHub.





Leave a Reply

Your email address will not be published. Required fields are marked *