Give an nxn array of elements such that each row is in ascending order and each column is in ascending order, devise an O(n) algorithm to determine if a given element x in the array. You may assume all elements in the nxn array are distinct.
Please tell me if somebody knows the solution to this problem.
Start at 1st row last column i.e. i=0, j = n-1
This is O(n). Explanation:
Start at first row and last column. i=0;j=n-1 Everytime x is less than currElement decrement j else increment i.