Sort by

recency

|

1713 Discussions

|

  • + 0 comments

    int result = (s + m -1) % n; if(result == 0){ return n; }else{ return result; } }

  • + 0 comments

    clean Rust:

    fn save_the_prisoner(n: i32, m: i32, s: i32) -> i32 {
       (s - 2 + m) % n + 1
    }
    
  • + 0 comments
    public static int saveThePrisoner(int n, int m, int s) {
            return ((s - 1 + m - 1) % n) + 1;
        }
    
  • + 0 comments

    Here is problem solution in Python, java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-save-the-prisoner-problem-solution.html

  • + 0 comments

    My Javascript solution:

    function saveThePrisoner(n, m, s) {

    return (s+m-1)%n || n;
    

    }