Cody

# Problem 16. Return the largest number that is adjacent to a zero

Solution 2038577

Submitted on 29 Nov 2019 by Liam Storan
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
a = [1, 5, 3, 0, 2, 7, 0, 8, 9, 1 0]; b = 8; assert(isequal(nearZero(a),b))

dope = 0 dope2 = -1 x = -1 1 5 3 0 2 7 0 8 9 1 0 -1 y = 1×13 logical array 0 0 0 0 1 0 0 1 0 0 0 1 0 z = 5 8 12 n = 3 maxers = -1 maxers2 = -1 maxers = 3 maxers = 3 7 maxers = 3 7 1 maxers2 = 2 maxers2 = 2 8 maxers2 = 2 8 -1 finalmax1 = 7 finalmax2 = 8

2   Pass
a = [5 4 -1 0 -2 0 -5 8]; b = -1; assert(isequal(nearZero(a),b));

dope = 5 dope2 = -6 x = -6 5 4 -1 0 -2 0 -5 8 -6 y = 1×10 logical array 0 0 0 0 1 0 1 0 0 0 z = 5 7 n = 2 maxers = -6 maxers2 = -6 maxers = -1 maxers = -1 -2 maxers2 = -2 maxers2 = -2 -5 finalmax1 = -1 finalmax2 = -2

3   Pass
a = [0 3 1 0 2 9]; b = 3; assert(isequal(nearZero(a),b));

dope = 0 dope2 = -1 x = -1 0 3 1 0 2 9 -1 y = 1×8 logical array 0 1 0 0 1 0 0 0 z = 2 5 n = 2 maxers = -1 maxers2 = -1 maxers = -1 maxers = -1 1 maxers2 = 3 maxers2 = 3 2 finalmax1 = 1 finalmax2 = 3

4   Pass
a = [1 0 2 0 3]; b = 3; assert(isequal(nearZero(a),b));

dope = 0 dope2 = -1 x = -1 1 0 2 0 3 -1 y = 1×7 logical array 0 0 1 0 1 0 0 z = 3 5 n = 2 maxers = -1 maxers2 = -1 maxers = 1 maxers = 1 2 maxers2 = 2 maxers2 = 2 3 finalmax1 = 2 finalmax2 = 3

5   Pass
a = [0 -1]; b = -1; assert(isequal(nearZero(a),b));

dope = 1 dope2 = -2 x = -2 0 -1 -2 y = 1×4 logical array 0 1 0 0 z = 2 n = 1 maxers = -2 maxers2 = -2 maxers = -2 maxers2 = -1 finalmax1 = -2 finalmax2 = -1

6   Pass
a = [0 -12 0 -7 0]; b = -7; assert(isequal(nearZero(a),b));

dope = 12 dope2 = -13 x = -13 0 -12 0 -7 0 -13 y = 1×7 logical array 0 1 0 1 0 1 0 z = 2 4 6 n = 3 maxers = -13 maxers2 = -13 maxers = -13 maxers = -13 -12 maxers = -13 -12 -7 maxers2 = -12 maxers2 = -12 -7 maxers2 = -12 -7 -13 finalmax1 = -7 finalmax2 = -7

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!