![]() |
VOOZH | about |
Given a matrix of m*n size, the task is to count all the rows in a matrix that are sorted either in strictly increasing order or in strictly decreasing order?
Examples :
Input : m = 4, n = 5
mat[m][n] = 1 2 3 4 5
4 3 1 2 6
8 7 6 5 4
5 7 8 9 10
Output: 3
The idea is simple and involves two traversals of matrix.
Below is the implementation of above idea.
3
Time Complexity : O(m*n)
Auxiliary space :O(1)
If you have another optimized approach to solve this problem then please share in comments.