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.
You should probably avoid the switch here unless Integer.compare() is guaranteed to return -1, 0, or 1 as output or you divide the result of Integer.compare() by Math.abs(x-y).
typically, you only get the guarantee of <0, 0, >0 (and not -1, 0, 1) because compare functions like this are usually implemented as: return a - b;.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cats and a Mouse
You are viewing a single comment's thread. Return to all comments →
You should probably avoid the switch here unless Integer.compare() is guaranteed to return -1, 0, or 1 as output or you divide the result of Integer.compare() by
Math.abs(x-y)
.typically, you only get the guarantee of <0, 0, >0 (and not -1, 0, 1) because compare functions like this are usually implemented as:
return a - b;
.