Sort by

recency

|

1710 Discussions

|

  • + 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;
    

    }

  • + 0 comments

    Here solution in c++, you can watch the explanation here : https://youtu.be/xoV2P0Pv9Fg

    Solution 1 :

    int saveThePrisoner(int n, int m, int s) {
        int c = (m % n) + s - 1 ;
        if ( c > n) c -= n;
        if ( c == 0) return n;
        return c;
    }
    

    Solution 2 :

    int saveThePrisoner(int n, int m, int s) {
        return (m - 1  + s - 1 ) % n + 1;
    }
    
  • + 0 comments

    C++ Solution:

    int saveThePrisoner(int n, int m, int s) {
        int warn = 0;
        warn = (m+(s-1)) % n; 
        if(warn == 0) warn = n;
        return warn;
    }
    
  • + 0 comments
    public static int saveThePrisoner(int n, int m, int s) {
        return (((((m % n) + (s - 1)) % n) + (n - 1)) % n) + 1;
    }