Cody

# Problem 1699. Find last zero for each column

Solution 454719

Submitted on 13 Jun 2014 by rifat
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 = 0; z_correct = 1; assert(isequal(lastzerorow(a),z_correct))

z = 1

2   Pass
%% a = 1; z_correct = 0; assert(isequal(lastzerorow(a),z_correct))

3   Pass
%% a = randi(1000,1000,1); z_correct = 0; assert(isequal(lastzerorow(a),z_correct))

4   Pass
%% a = [0;1;0;2;0;3;0;4;0;5;0;6;0;7;0;8;0;9;0;10]; z_correct = 19; assert(isequal(lastzerorow(a),z_correct))

z = 19

5   Pass
%% n = randi(1000); a = tril(ones(n)); z_correct = 0:n-1; assert(isequal(lastzerorow(a),z_correct))

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

6   Pass
%% n = randi(1000); a = tril(ones(n),-1); z_correct = 1:n; assert(isequal(lastzerorow(a),z_correct))

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

7   Fail
%% n = randi(1000); d = randi(n-1); a = tril(ones(n),-d); z_correct = min((0:n-1)+d,n); assert(isequal(lastzerorow(a),z_correct))

z = 266 z = 266 267 z = 266 267 268 z = 266 267 268 269 z = 266 267 268 269 270 z = 266 267 268 269 270 271 z = 266 267 268 269 270 271 272 z = 266 267 268 269 270 271 272 273 z = 266 267 268 269 270 271 272 273 274 z = 266 267 268 269 270 271 272 273 274 275 z = 266 267 268 269 270 271 272 273 274 275 276 z = 266 267 268 269 270 271 272 273 274 275 276 277 z = 266 267 268 269 270 271 272 273 274 275 276 277 278 z = 266 267 268 269 270 271 272 273 274 275 276 277 278 279 z = 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 z = 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Column 17 282 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 18 282 283 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 19 282 283 284 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 20 282 283 284 285 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 21 282 283 284 285 286 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 22 282 283 284 285 286 287 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 23 282 283 284 285 286 287 288 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 24 282 283 284 285 286 287 288 289 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 25 282 283 284 285 286 287 288 289 290 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 26 282 283 284 285 286 287 288 289 290 291 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 27 282 283 284 285 286 287 288 289 290 291 292 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 28 282 283 284 285 286 287 288 289 290 291 292 293 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 29 282 283 284 285 286 287 288 289 290 291 292 293 294 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 30 282 283 284 285 286 287 288 289 290 291 292 293 294 295 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 31 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 32 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 32 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 Column 33 298 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 32 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 Columns 33 through 34 298 299 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 32 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 Columns 33 through 35 298 299 300 z = Columns 1 through 16 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 Columns 17 through 32 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 Col