You are viewing a single comment's thread. Return to all 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; }
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 →
Here solution in c++, you can watch the explanation here : https://youtu.be/xoV2P0Pv9Fg
Solution 1 :
Solution 2 :