Showing:
Handle Score
@Ibrahim Nash 6560
@mb1973 5777
@Quandray 5275
@akhayrutdinov 5111
@saiujwal13083 5074
@kirtidee18 4398
@sanjay05 3762
@mantu_singh 3654
@gfgaccount 3601
@marius_valentin_dragoi 3525
Count Sorted Rows
Basic Accuracy: 36.03% Submissions: 606 Points: 1

Given two integers N and M and a matrix of dimensions N*M. 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.

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