Hackerrank - Sherlock and Squares


Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /nfsmnt/hosting2_2/a/b/abebc507-bf25-4cf8-8cfa-a3d31b5acb3d/pidanic.com/web/wp-content/plugins/latex/latex.php on line 47

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /nfsmnt/hosting2_2/a/b/abebc507-bf25-4cf8-8cfa-a3d31b5acb3d/pidanic.com/web/wp-content/plugins/latex/latex.php on line 49

Hackerrank - Problem Statement

A description of the problem can be found on Hackerrank.

Solution

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:
.

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.

Java

JavaScript

Scala

Ruby

Leave a Reply