Sort by

recency

|

1705 Discussions

|

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

    Perl:

    sub saveThePrisoner {
        my ($n, $m, $s) = @_;
        
        return ($s + $m - 1) % $n == 0 ? $n : ($s + $m - 1) % $n;
    }
    
  • + 0 comments

    Python 3

    def saveThePrisoner(n, m, s):

    l = m + s -1
    l = l % n 
    if l == 0:
        l = n
    
    return l
    
  • + 0 comments

    Java one line cryptic solution:

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

    Save the Prisoner!" sounds like an intense and engaging concept! When it comes to brand strategy and development, it's all about creating a strong identity that resonates with your audience. Whether it's a game, campaign, or movement, a well-thought-out brand strategy ensures it stands out and grows over time. Excited to see where this goes!