• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
June 13, 2022 |25.9K Views
Search in a row wise and column wise sorted matrix
  Share   Like
Description
Discussion

Given an n x n matrix and a number x, find the position of x in the matrix if it is present in it. Otherwise, print “Not Found”. In the given matrix, every row and column is sorted in increasing order. The designed algorithm should have linear time complexity.

Example:

Input: mat[4][4] = { {10, 20, 30, 40},
                              15, 25, 35, 45},
                              {27, 29, 37, 48},
                            {32, 33, 39, 50}}
          x = 29
Output: Found at (2, 1)
Explanation: Element at (2,1) is 29

Search in a row wise and column wise sorted matrix : https://www.geeksforgeeks.org/search-in-row-wise-and-column-wise-sorted-matrix/

Read More