Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 323697

Submitted on 26 Sep 2013 by Alfonso Nieto-Castanon

Correct

30Size
Leading solution size is 13.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
1
ans =
     1
2
Pass
 
%%
assert(isequal(true,isLIFO([1;2],[4;3])));
2
ans =
     2
3
Pass
 
%%
assert(isequal(false,isLIFO([1;2],[3;4])));
3
ans =
     3
4
Pass
 
%%
for i=1:100
    In = randi(20,100,1);
    Out = randi(20,100,1);
    valid = In<Out;
    In=In(valid);
    Out=Out(valid);
    TF=true;
    for k=1:numel(In)-1
        for l=k+1:numel(In)
            if (In(k)<In(l)) && (Out(k) < Out(l))
                TF = false;
            end
        end
    end
    assert(isequal(TF,isLIFO(In,Out)));
end
4
ans =
     4
5
Pass
 
%%
assert(isequal(true,isLIFO([1;2],[3;3])));
5
ans =
     5
6
Pass
 
%%
assert(isequal(true,isLIFO([2;2],[4;3])));
6
ans =
     6
7
Pass
 
%%
assert(isequal(true,isLIFO([2;2],[7;6])));