Hackerrank - Cats and a Mouse


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

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

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

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

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

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

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

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

Cats and the mouse moves with the same speed. Suppose it is by 1 on x-axis.
Lets define the difference between their positions: (cat A, mouse), (cat B, mouse).


where , , are coordinates on -axis.

The results
- If -> "Mouse C"
- If -> "Cat A"
- Else -> "Cat B"

I created solution in:

All solutions are also available on my GitHub profile.

Scala

Java

Javascript

Leave a Reply