Arrays challenege (kth root)

sir have a look plz ,is there any method faster than it…

i m getting TLE in one of my test case…

import java.util.Scanner;

public class Main {
static Scanner s=new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method stub
int n=s.nextInt();
double[] ans=new double[n];
int[] pow=new int[n];
for(int i=0;i<n ;i++) {
ans[i] =s.nextDouble();
pow[i] =s.nextInt();
}

for(int j=0;j<n;j++) {
int fin=0;
double res=0;
for(int i=1;res <=ans[j] && i<=ans[j]; i++) {
res=Math.pow(i,pow[j]);
if(res <=ans[j]) {
fin=i;
}
}
System.out.println(fin);
}

}

}

@sameeksha,

We will aplly binary search in this problem. For every possible mid obtained by using binary search we will check of it is the best suitable candidate or not for becoming the Kth root and then we reduce the search space of the binary search according to the mid value. If mid^k is greater than N then we will find the best suitable value from left to mid-1 otherwise we will find much larger value by finding it from mid+1 to right.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.