#codingexercise
In a rowwise and columnwise sorted matrix of distinct increasing integers, find if a given integer exists.
In a rowwise and columnwise sorted matrix of distinct increasing integers, find if a given integer exists.
Tuple<int,int> GetPositionRowWise(int[,] A, int Rows, int Cols, int X)
{
var ret = new Tuple<int, int>(){-1,-1};
// x, y coordinates
for (int i =0; i < Rows; i++)
{
int index = binary_search(A, cols, i, X);
if ( index != -1)
{
ret.first = i;
ret.second = index;
break;
}
}
return ret;
}
No comments:
Post a Comment