We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Cats and a Mouse
Cats and a Mouse
Sort by
recency
|
1241 Discussions
|
Please Login in order to post a comment
function catAndMouse(x, y, z) {
}
**Java Code : // Complete the catAndMouse function below.
static String catAndMouse(int x, int y, int z) { int catADistance = Math.abs(x-z); int catBDistance = Math.abs(z-y); return (catADistance == catBDistance)?"Mouse C":(catADistance>catBDistance)? "Cat B": "Cat A" ; }
JavaSolution
Hi there! Here's my Java solution for the challenge.
https://github.com/eduardocintra/hacker-rank-solutions/blob/master/src/br/com/eduardocintra/easy/catsandamouse/CatsAndAMouse.java
PYTHON 3 def catAndMouse(x, y, z): if abs(x-z)>abs(y-z): return "Cat B" elif abs(x-z)==abs(y-z): return "Mouse C" else: return "Cat A"