Skip to content

Instantly share code, notes, and snippets.

@rachidelaid
Created May 26, 2022 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rachidelaid/73dad78e9e78bbca4fe7daeb37b5e366 to your computer and use it in GitHub Desktop.
Save rachidelaid/73dad78e9e78bbca4fe7daeb37b5e366 to your computer and use it in GitHub Desktop.
this is the solution to the cats and mouse problem in hackerrank. https://www.hackerrank.com/challenges/cats-and-a-mouse/problem?isFullScreen=true
function catAndMouse(x, y, z) {
const diffA = Math.abs(z-x);
const diffB = Math.abs(z-y);
if(diffA === diffB) return "Mouse C";
return diffA < diffB ? "Cat A" : "Cat B";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment