Thursday, May 31, 2018

#codingexercise
In a rowwise and columnwise sorted matrix of distinct increasing integers, find if a given integer exists. 
Tuple<int,intGetPositionRowWise(int[,] A, int Rows, int Cols, int X) 
{ 
var ret = new Tuple<intint>(){-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