Please,someone explain me why my I am getting Time Limit Exceeded(TLE)

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{

static int solve(int n,int p,int k)
{
    //int[] arr = new int[10];
    int count = 1;
    int count1 = 2;
    int itr = 1;
    int i = 0;
    int j = k;
    while(itr <= n)
    {
        if(p<k)
        {
            if(p == i)
            {
                return count;
            }
            i++;
        }
        else if(p>=k)
        {
            if(p == j)
            {
                return count1;   
            }
            j++;
        }
        count1 = count1 + 2;
        count = count + 2;
        itr++;
    }
    return 0;
}

public static void main (String[] args) throws java.lang.Exception
{
	Scanner sc = new Scanner(System.in);
	int testcase =  sc.nextInt();
	
	while(testcase-->0)
	{
	    int n = sc.nextInt();
	    int p = sc.nextInt();
	    int k = sc.nextInt();
	    
	    int answer = solve(n,p,k);
	    System.out.println(answer);
	}
	
}

}

If you are trying to solve the august long challenge, we shouldn’t discuss it now.
But I think the problem is with O(n) runtime.

My code contains only one loop and according to ‘p’ only one condition will executes