Hackerrank – Cats and a Mouse

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

    \[d_{am} = |a - m|\]

    \[d_{bm} = |b - m|\]

where

    \[a\]

,

    \[b\]

,

    \[m\]

are coordinates on

    \[x\]

-axis.

The results
– If

    \[d_{am} == d_{bm}\]

-> "Mouse C"
– If

    \[d_{am} \lt d_{bm}\]

-> "Cat A"
– Else -> "Cat B"

I created solution in:

All solutions are also available on my GitHub profile.

Scala

Java

Javascript

Leave a Reply

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