Cody

# Problem 42633. Cumulative maximum of an array

Solution 1945986

Submitted on 22 Sep 2019 by Augusto Mazzei
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('cumax.m'); assert(isempty(strfind(filetext,'cummin'))) assert(isempty(strfind(filetext,'cummax'))) assert(isempty(strfind(filetext,'feval')))

2   Pass
x = randi(100); assert(isequal(cumax(x),cummax(x))) assert(isequal(cumax(x,1),cummax(x,1))) assert(isequal(cumax(x,2),cummax(x,2))) assert(isequal(cumax(x,1,'reverse'),cummax(x,1,'reverse'))) assert(isequal(cumax(x,2,'reverse'),cummax(x,2,'reverse'))) assert(isequal(cumax(x,'reverse'),cummax(x,'reverse')))

dir = 1×0 empty double row vector dir = 1×0 empty double row vector dir = 1×0 empty double row vector dir = 1×0 empty double row vector dir = 1×0 empty double row vector dir = 1×0 empty double row vector

3   Pass
x = randi(100,randi([2 100]),1); assert(isequal(cumax(x),cummax(x))) assert(isequal(cumax(x,1),cummax(x,1))) assert(isequal(cumax(x,2),cummax(x,2))) assert(isequal(cumax(x,1,'reverse'),cummax(x,1,'reverse'))) assert(isequal(cumax(x,2,'reverse'),cummax(x,2,'reverse'))) assert(isequal(cumax(x,'reverse'),cummax(x,'reverse')))

dir = 1 dir = 1 dir = 1 dir = 1 dir = 2 dir = 1 dir = 1 rev = 1 dir = 1 dir = 2 rev = 1 dir = 1 rev = 1

4   Pass
x = randi(100,1,randi([2 100])); assert(isequal(cumax(x),cummax(x))) assert(isequal(cumax(x,1),cummax(x,1))) assert(isequal(cumax(x,2),cummax(x,2))) assert(isequal(cumax(x,1,'reverse'),cummax(x,1,'reverse'))) assert(isequal(cumax(x,2,'reverse'),cummax(x,2,'reverse'))) assert(isequal(cumax(x,'reverse'),cummax(x,'reverse')))

dir = 2 dir = 2 dir = 1 dir = 2 dir = 2 dir = 2 dir = 1 rev = 1 dir = 2 dir = 2 rev = 1 dir = 2 rev = 1

5   Pass
x = magic(10); assert(isequal(cumax(x),cummax(x))) assert(isequal(cumax(x,1),cummax(x,1))) assert(isequal(cumax(x,2),cummax(x,2))) assert(isequal(cumax(x,1,'reverse'),cummax(x,1,'reverse'))) assert(isequal(cumax(x,2,'reverse'),cummax(x,2,'reverse'))) assert(isequal(cumax(x,'reverse'),cummax(x,'reverse')))

dir = 1 dir = 1 dir = 1 dir = 1 dir = 2 dir = 1 dir = 1 rev = 1 dir = 1 dir = 2 rev = 1 dir = 1 rev = 1

6   Pass
x = []; assert(isequal(cumax(x),cummax(x))) assert(isequal(cumax(x,1),cummax(x,1))) assert(isequal(cumax(x,2),cummax(x,2))) assert(isequal(cumax(x,1,'reverse'),cummax(x,1,'reverse'))) assert(isequal(cumax(x,2,'reverse'),cummax(x,2,'reverse'))) assert(isequal(cumax(x,'reverse'),cummax(x,'reverse')))

dir = 1×0 empty double row vector dir = 1×0 empty double row vector dir = 1×0 empty double row vector dir = 1×0 empty double row vector dir = 1×0 empty double row vector dir = 1×0 empty double row vector