bharat.chandra26
BAN USER
Comments (3)
Reputation 10
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
The matrix is sorted row-wise also means you consider the elements in each column, they are also sorted top down. So, we can first perform a binary search on say the first column, reach a particular row and then perform another binary search on the row to get to the required element.
For a MxN matrix, this solves the problem in O(log M) + O (log N)
You just need to search the required row !!
Comment hidden because of low score. Click to expand.
1
of 1 vote
A C# recursive function to reverse an input string
public string Reverse(string input)
{
if (input.Length == 1)
{
return input;
}
else
return string.Concat(input[input.Length-1], Reverse(input.Substring(0,input.Length-1)));
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Yes eugene. That's correct. This works only for the case where the elements are sorted row wise and also column wise. Basically I meant I have some completely sorted matrix as we go through the rows down the matrix. Sorry I missed the explicitly stated point that the elements are not sorted column-wise
- bharat.chandra26 December 23, 2012