![]() |
VOOZH | about |
Given a matrix mat[n][m] and an element target. return true if the target is present in the matrix, else return false.
Examples:
Input : mat[][] = { {10, 51, 9},
{14, 20, 21},
{30, 24, 43} }
target = 14
Output: Found
Input : mat[][] = {{31, 5, 9, 11},
{14, 7, 21, 26},
{30, 4, 43, 50} }
target = 42
Output: Not Found
We traverse the mat[][] and compare target with every element of the matrix. If matches, then return true If we reach the end we will return false.
Found
Time Complexity : O(n * m), where n and m are the rows and column of matrix.
Auxiliary Space : O(1)