• + 5 comments

    My code passes two testcases and I believe the logic is right.But for other testcases it gives "terminated due to timeout error". Can you tell what's going wrong ?

    import java.io.*;
    import java.util.*;
    import java.text.*;
    import java.math.*;
    import java.util.regex.*;
    
    public class Solution {
    
        static int saveThePrisoner(int n, int m, int s){
            int returner=0;
            for(int x=s;x<=n;x++)
                {
                m--;
                if(m>0 && x==n)
                    {
                    x=1;
                }
                if(m==0)
                    {
                    returner=x;
                    break;
                }
            }
            return returner;
        }
        
    
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int t = in.nextInt();
            for(int a0 = 0; a0 < t; a0++){
                int n = in.nextInt();
                int m = in.nextInt();
                int s = in.nextInt();
                int result = saveThePrisoner(n, m, s);
                System.out.println(result);
            }
        }
    }