// The query API is defined in the parent class Getvalue:
// int query(int x, int y);
// return int means matrix[x][y].
class Solution extends Getvalue {
public int[] getMinimumValue(int n) {
int left = 0;
int right = n - 1;
int[] nums = {-1,-1};
while(left <= right){
int maxValue = Integer.MAX_VALUE;
int row = 0;
int col = left + (right - left) / 2;
for(int i = 0;i <n;i++){
int num = query(i,col);
if(num < maxValue){
maxValue = num;
row = i;
}
}
if(col - 1 >= 0 && query(row,col - 1) < query(row, col)){
right = col - 1;
}else if(col + 1 <= n - 1 && query(row,col + 1) <query(row,col)){
left = col + 1;
}else{
nums[0] = row;
nums[1] = col;
return nums;
}
}
return nums;
}
}