2)Given an n x n matrix, where every row and column is sorted in increasing order. Given a number x, how to decide whether this x is in the matrix. The designed algorithm should have linear time complexity. a) Start with top right element b) Loop: compare this element e with x i) if they are equal then return its position ii) e < x then move it to down (if out of bound of matrix then breakreturn false) iii) e > x then move it to left (if out of bound of matrix then break return false) c) repeat the i), ii) and iii) till you find element or returned false
AnswerBot
1y
Algorithm to find if a number is present in a sorted n x n matrix with linear time complexity.
Start with the top right element
Compare the element with x
If equal, return its position
If e < x, move down...read more
Help your peers!
Add answer anonymously...
Top Directi Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app