P17229 [GeeksforGeeks] Count sorted rows2702
普及-
题目描述

Given two integers N and M and a matrix of dimensions NM. Count all the rows in a matrix that are sorted either in strictly increasing order or in strictly decreasing order.
Example 1:
Input:
N=3,M=3
Mat=[[1,2,3],[6,5,4],[7,9,8]]
Output:
2
Explanation:
The first row is sorted in strictly
increasing order while the second row
is sorted in strictly decreasing order.
Example 2:
Input:
N=3,M=3
Mat=[[1,2,3],[4,5,6],[7,8,9]]
Output:
3
Explanation:
All the rows are sorted in strictly
increasing order.
Your Task:
You don't need to read input or print anything.Your task is to complete the function sortedCount() which takes the two integers N,M and the matrix Mat as input parameters and returns the number of rows which are sorted in either strictly increasing order or strictly decreasing order.
Expected Time Complexity:O(N
M)
Expected Auxillary Space:O(1)

Constraints:
1<=N,M,Mat[i][j]<=1000

输入格式

见题面

输出格式

见题面

样例输入
N=3,M=3 Mat=[[1,2,3],[6,5,4],[7,9,8]]
样例输出
2