gravatar

Blog # 52 : Searching in 2D array

Given 2D array with integers sorted both horizontally and vertically. Devise an efficient algorithm to search for key in the 2D array. What is the complexity ? 

Eg. 

    1 4 7 13 

    2 5 9 15 

    3 6 10 16

Click here to see the solution.
p.s. - For Remarks please hit the given link once. For Hint, hit it twice and for the solution, hit it thrice.




Courtesy: Vibhaj