Cody

# Problem 42802. Rolling maximums above a threshold

You are given either a vector or a 2-D matrix M and a threshold value of t. Write a script that will calculate how many times the maximum value increases between the first time your threshold value is exceeded and the end of the matrix. If you are given a 2-D matrix, go down the columns first and then the rows.

For example, M=magic(7), and your threshold=30

```M=
```
```[   30    39    48     1    10    19    28;
38    47     7     9    18    27    29;
46     6     8    17    26    35    37;
5    14    16    25    34    36    45;
13    15    24    33    42    44     4;
21    23    32    41    43     3    12;
22    31    40    49     2    11    20];
```

The first value that's higher than your threshold is 38. The 30 at the start of the matrix does not exceed your threshold, so it does not count.

Then going down the first column 46>38, so you have another new maximum.

The next value higher than the threshold is 39, but that is less than 46, so your matrix maximum is still 46 until you reach 47. The third column contains 48, and the fourth column contains 49. There are no numbers higher than 49 in the matrix, so your matrix maximum changes five times.

38-->46-->47-->48-->49.

The output to your script would be n=5. You do not need to store what the maxima are, only how many times it changes. If there are no numbers higher than the threshold in your matrix, the output should be zero.

### Solution Stats

89.47% Correct | 10.53% Incorrect
Last Solution submitted on Mar 13, 2020