Sort by

recency

|

1695 Discussions

|

  • + 0 comments

    C# return (m+s-1) > n ?(((m+s-1)%n) == 0 ? n:(m+s-1)%n ):(m+s-1);

  • + 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
    function saveThePrisoner(n, m, s) {
        let pos = s + (m % n) - 1;
        return (pos == 0 || pos > n) ? Math.abs(pos - n) : pos;
    }
    
  • + 0 comments
    function saveThePrisoner(prisoners, candies, start) {
        // Write your code here
        let lastPrisoner = (start + candies - 1) % prisoners; 
        return lastPrisoner ? lastPrisoner : prisoners; 
    }
    
  • + 0 comments

    def saveThePrisoner(n, m, s):

    m = m - 1
    p = s + m 
    r = p % n 
    
    if r == 0:
        return n
    else:
        return r