Hackerrank – Kangaroo

Hackerrank – Problem Statement

A description of the problem can be found on Hackerrank.

Solution

There are two checks:

  • I checked if

        \[v_1\]

    is less then

        \[v_2\]

    and immediatelly print "NO". That means, kangaroo 1 would be never able to reach kangaroo 2.

  • I calculated differences between kangaroo positions

        \[x_d\]

    and their jumps

        \[v_d\]

    . If

        \[x_d % v_d == 0\]

    than kangaroo 1 will reach kangaroo 2. Else "NO".

I created solution in:

All solutions are also available on my GitHub.

Java

JavaScript

Scala

Ruby

Leave a Reply

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