You are viewing a single comment's thread. Return to all comments →
function saveThePrisoner($n, $m, $s) { $remainingCandies = $m % $n; if ($remainingCandies == 0) { return ($s - 1 == 0) ? $n : $s - 1; } else { $finalPosition = $s + $remainingCandies - 1; return ($finalPosition > $n) ? $finalPosition - $n : $finalPosition ; } }
Or
function saveThePrisoner($n, $m, $s) { $result = ($s + $m - 1) % $n; return $result === 0 ? $n : $result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Save the Prisoner!
You are viewing a single comment's thread. Return to all comments →
Or