Given an integer 'K' and a row-wise sorted 2-D Matrix i.e. the matrix has the following properties:
- Integers in each row are sorted from left to right.
- The first integer of each row is greater than the last integer of the previous row.
The task is to find whether the integer 'K' is present in the matrix or not. If present then print 'Found' else print 'Not found'.
Examples:
Input: mat = {
{1, 3, 5, 7},
{10, 11, 16, 20},
{23, 30, 34, 50}}
K = 3
Output: Found
Input: mat = {
{1, 3, 5, 7},
{10, 11, 16, 20},
{23, 30, 34, 50}}
K = 13
Output: Not found
Please refer Search element in a sorted 2D array for three different approaches to solve this problem.
Please refer Searching Algorithms for 2D Arrays (Matrix) for searching in an unsorted, sorted and semi-sorted arrays.