Cody

# Problem 1699. Find last zero for each column

Solution 1627471

Submitted on 14 Sep 2018 by Michael Cappello
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))

q = 1 z = 1

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

q = [] z = 0

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

q = 0×1 empty double column vector z = 0

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))

q = 19 z = 19

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

q = 0×1 empty double column vector q = 1 q = 2 q = 3 q = 4 q = 5 q = 6 q = 7 q = 8 q = 9 q = 10 q = 11 q = 12 q = 13 q = 14 q = 15 q = 16 q = 17 q = 18 q = 19 q = 20 q = 21 q = 22 q = 23 q = 24 q = 25 q = 26 q = 27 q = 28 q = 29 q = 30 q = 31 q = 32 q = 33 q = 34 q = 35 q = 36 q = 37 q = 38 q = 39 q = 40 q = 41 z = Columns 1 through 30 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Columns 31 through 42 30 31 32 33 34 35 36 37 38 39 40 41

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

q = 1 q = 2 q = 3 q = 4 q = 5 q = 6 q = 7 q = 8 q = 9 q = 10 q = 11 q = 12 q = 13 q = 14 q = 15 q = 16 q = 17 q = 18 q = 19 q = 20 q = 21 q = 22 q = 23 q = 24 q = 25 q = 26 q = 27 q = 28 q = 29 q = 30 q = 31 q = 32 q = 33 q = 34 q = 35 q = 36 q = 37 q = 38 q = 39 q = 40 q = 41 q = 42 q = 43 q = 44 q = 45 q = 46 q = 47 q = 48 q = 49 q = 50 q = 51 q = 52 q = 53 q = 54 q = 55 q = 56 q = 57 q = 58 q = 59 q = 60 q = 61 q = 62 q = 63 q = 64 q = 65 q = 66 q = 67 q = 68 q = 69 q = 70 q = 71 q = 72 q = 73 q = 74 q = 75 q = 76 q = 77 q = 78 q = 79 q = 80 q = 81 q = 82 q = 83 q = 84 q = 85 q = 86 q = 87 q = 88 q = 89 q = 90 q = 91 q = 92 q = 93 q = 94 q = 95 q = 96 q = 97 q = 98 q = 99 q = 100 q = 101 q = 102 q = 103 q = 104 q = 105 q = 106 q = 107 q = 108 q = 109 q = 110 q = 111 q = 112 q = 113 q = 114 q = 115 q = 116 q = 117 q = 118 q = 119 q = 120 q = 121 q = 122 q = 123 q = 124 q = 125 q = 126 q = 127 q = 128 q = 129 q = 130 q = 131 q = 132 q = 133 q = 134 q = 135 q = 136 q = 137 q = 138 q = 139 q = 140 q = 141 q = 142 q = 143 q = 144 q = 145 q = 146 q = 147 q = 148 q = 149 q = 150 q = 151 q = 152 q = 153 q = 154 q = 155 q = 156 q = 157 q = 158 q = 159 q = 160 q = 161 q = 162 q = 163 q = 164 q = 165 q = 166 q = 167 q = 168 q = 169 q = 170 q = 171 q = 172 q = 173 q = 174 q = 175 q = 176 q = 177 q = 178 q = 179 q = 180 q = 181 q = 182 q = 183 q = 184 q = 185 q = 186 q = 187 q = 188 q = 189 q = 190 q = 191 q = 192 q = 193 q = 194 q = 195 q = 196 q = 197 q = 198 q = 199 q = 200 q = 201 q = 202 q = 203 q = 204 q = 205 q = 206 q = 207 q = 208 q = 209 q = 210 q = 211 q = 212 q = 213 q = 214 q = 215 q = 216 q = 217 q = 218 q = 219 q = 220 q = 221 q = 222 q = 223 q = 224 q = 225 q = 226 q = 227 q = 228 q = 229 q = 230 q = 231 q = 232 q = 233 q = 234 q = 235 q = 236 q = 237 q = 238 q = 239 q = 240 q = 241 q = 242 q = 243 q = 244 q = 245 q = 246 q = 247 q = 248 q = 249 q = 250 q = 251 q = 252 q = 253 q = 254 q = 255 q = 256 q = 257 q = 258 q = 259 q = 260 q = 261 q = 262 q = 263 q = 264 q = 265 q = 266 q = 267 q = 268 q = 269 q = 270 q = 271 q = 272 q = 273 q = 274 q = 275 q = 276 q = 277 q = 278 q = 279 q = 280 q = 281 q = 282 q = 283 q = 284 q = 285 q = 286 q = 287 q = 288 q = 289 q = 290 q = 291 q = 292 q = 293 q = 294 q = 295 q = 296 q = 297 q = 298 q = 299 q = 300 q = 301 q = 302 q = 303 q = 304 q = 305 q = 306 q = 307 q = 308 q = 309 q = 310 q = 311 q = 312 q = 313 q = 314 q = 315 q = 316 q = 317 q = 318 q = 319 q = 320 q = 321 q = 322 q = 323 q = 324 q = 325 q = 326 q = 327 q = 328 q = 329 q = 330 q = 331 q = 332 q = 333 q = 334 q = 335 q = 336 q = 337 q = 338 q = 339 q = 340 q = 341 q = 342 q = 343 q = 344 q = 345 q = 346 q = 347 q = 348 q = 349 q = 350 q = 351 q = 352 q = 353 q = 354 q = 355 q = 356 q = 357 q = 358 q = 359 q = 360 q = 361 q = 362 q = 363 q = 364 q = 365 q = 366 q = 367 q = 368 q = 369 q = 370 q = 371 q = 372 q = 373 q = 374 q = 375 q = 376 q = 377 q = 378 q = 379 q = 380 q = 381 q = 382 q = 383 q = 384 q = 385 q = 386 q = 387 q = 388 q = 389 q = 390 q = 391 q = 392 q = 393 q = 394 q = 395 q = 396 q = 397 q = 398 q = 399 q = 400 q = 401 q = 402 q = 403 q = 404 q = 405 q = 406 q = 407 q = 408 q = 409 q = 410 q = 411 q = 412 q = 413 q = 414 q = 415 q = 416 q = 417 q = 418 q = 419 q = 420 q = 421 q = 422 q = 423 q = 424 q = 425 q = 426 q = 427 q = 428 q = 429 q = 430 q = 431 q = 432 q = 433 q = 434 q = 435 q = 436 q = 437 q = 438 q = 439 q = 440 q = 441 q = 442 q = 443 q = 444 q = 445 q = 446 q = 447 q = 448 q = 449 q = 450 q = 451 q = 452 q = 453 q = 454 q = 455 q = 456 q = 457 q = 458 q = 459 q = 460 q = 461 q = 462 q = 463 q = 464 q = 465 q = 466 q = 467 q = 468 q = 469 q = 470 q = 471 q = 472 q = 473 q = 474 q = 475 q = 476 q = 477 q = 478 q = 479 q = 480 q = 481 q = 482 q = 483 q = 484 q = 485 q = 486 q = 487 q = 488 q = 489 q = 490 q = 491 q = 492 q = 493 q = 494 q = 495 q = 496 q = 497 q = 498 q = 499 q = 500 q = 501 q = 502 q = 503 q = 504 q = 505 q = 506 q = 507 q = 508 q = 509 q = 510 q = 511 q = 512 q = 513 q = 514 q = 515 q = 516 q = 517 q = 518 q = 519 q = 520 q = 521 q = 522 q = 523 z = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Columns 31 through 60 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 Columns 61 through 90 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 Columns 91 through 120 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 Columns 121 through 150 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 Columns 151 through 180 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 Columns 181 through 210 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 Columns 211 through 240 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 Columns 241 through 270 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 Columns 271 through 300 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 Columns 301 through 330 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 Columns 331 through 360 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 Columns 361 through 390 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 ...

7   Pass
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))

q = 560 q = 561 q = 562 q = 563 q = 564 q = 565 q = 566 q = 567 q = 568 q = 569 q = 570 q = 571 q = 572 q = 573 q = 574 q = 575 q = 576 q = 577 q = 578 q = 579 q = 580 q = 581 q = 582 q = 583 q = 584 q = 585 q = 586 q = 587 q = 588 q = 589 q = 590 q = 591 q = 592 q = 593 q = 594 q = 595 q = 596 q = 597 q = 598 q = 599 q = 600 q = 601 q = 602 q = 603 q = 604 q = 605 q = 606 q = 607 q = 608 q = 609 q = 610 q = 611 q = 612 q = 613 q = 614 q = 615 q = 616 q = 617 q = 618 q = 619 q = 620 q = 621 q = 622 q = 623 q = 624 q = 625 q = 626 q = 627 q = 628 q = 629 q = 630 q = 631 q = 632 q = 633 q = 634 q = 635 q = 636 q = 637 q = 638 q = 639 q = 640 q = 641 q = 642 q = 643 q = 644 q = 645 q = 646 q = 647 q = 648 q = 649 q = 650 q = 651 q = 652 q = 653 q = 654 q = 655 q = 656 q = 657 q = 658 q = 659 q = 660 q = 661 q = 662 q = 663 q = 664 q = 665 q = 666 q = 667 q = 668 q = 669 q = 670 q = 671 q = 672 q = 673 q = 674 q = 675 q = 676 q = 677 q = 678 q = 679 q = 680 q = 681 q = 682 q = 683 q = 684 q = 685 q = 686 q = 687 q = 688 q = 689 q = 690 q = 691 q = 692 q = 693 q = 694 q = 695 q = 696 q = 697 q = 698 q = 699 q = 700 q = 701 q = 702 q = 703 q = 704 q = 705 q = 706 q = 707 q = 708 q = 709 q = 710 q = 711 q = 712 q = 713 q = 714 q = 715 q = 716 q = 717 q = 718 q = 719 q = 720 q = 721 q = 722 q = 723 q = 724 q = 725 q = 726 q = 727 q = 728 q = 729 q = 730 q = 731 q = 732 q = 733 q = 734 q = 735 q = 736 q = 737 q = 738 q = 739 q = 740 q = 741 q = 742 q = 743 q = 744 q = 745 q = 746 q = 747 q = 748 q = 749 q = 750 q = 751 q = 752 q = 753 q = 754 q = 755 q = 756 q = 757 q = 758 q = 759 q = 760 q = 761 q = 762 q = 763 q = 764 q = 765 q = 766 q = 767 q = 768 q = 769 q = 770 q = 771 q = 772 q = 773 q = 774 q = 775 q = 776 q = 777 q = 778 q = 779 q = 780 q = 781 q = 782 q = 783 q = 784 q = 785 q = 786 q = 787 q = 788 q = 789 q = 790 q = 791 q = 792 q = 793 q = 794 q = 795 q = 796 q = 797 q = 798 q = 799 q = 800 q = 801 q = 802 q = 803 q = 804 q = 805 q = 806 q = 807 q = 808 q = 809 q = 810 q = 811 q = 812 q = 813 q = 814 q = 815 q = 816 q = 817 q = 818 q = 819 q = 820 q = 821 q = 822 q = 823 q = 824 q = 825 q = 826 q = 827 q = 828 q = 829 q = 830 q = 831 q = 832 q = 833 q = 834 q = 835 q = 836 q = 837 q = 838 q = 839 q = 840 q = 841 q = 842 q = 843 q = 844 q = 845 q = 846 q = 847 q = 848 q = 849 q = 850 q = 851 q = 852 q = 853 q = 854 q = 855 q = 856 q = 857 q = 858 q = 859 q = 860 q = 861 q = 862 q = 863 q = 864 q = 865 q = 866 q = 867 q = 868 q = 869 q = 870 q = 871 q = 872 q = 873 q = 874 q = 875 q = 876 q = 877 q = 878 q = 879 q = 880 q = 881 q = 882 q = 883 q = 884 q = 885 q = 886 q = 887 q = 888 q = 889 q = 890 q = 891 q = 892 q = 893 q = 894 q = 895 q = 896 q = 897 q = 898 q = 899 q = 900 q = 901 q = 902 q = 903 q = 904 q = 905 q = 906 q = 907 q = 908 q = 909 q = 910 q = 911 q = 912 q = 913 q = 914 q = 915 q = 916 q = 917 q = 918 q = 919 q = 920 q = 921 q = 922 q = 923 q = 924 q = 925 q = 926 q = 927 q = 928 q = 929 q = 930 q = 931 q = 932 q = 933 q = 934 q = 935 q = 936 q = 937 q = 938 q = 939 q = 940 q = 941 q = 942 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = 943 q = ...

8   Pass
a = magic(10)-1; z_correct = [0 0 1 0 0 0 0 0 0 0]; assert(isequal(lastzerorow(a),z_correct))

q = 0×1 empty double column vector q = 0×1 empty double column vector q = 1 q = 0×1 empty double column vector q = 0×1 empty double column vector q = 0×1 empty double column vector q = 0×1 empty double column vector q = 0×1 empty double column vector q = 0×1 empty double column vector q = 0×1 empty double column vector z = 0 0 1 0 0 0 0 0 0 0

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

q = 5 q = 4 q = 0×1 empty double column vector q = 3 z = 5 4 0 3

10   Pass
a = [0 0 0 0 -4 0 0 0 0; 0 0 0 -3 -3 -3 0 0 0; 0 0 -2 3 -2 2 2 0 0; 0 -1 2 -1 1 -1 -1 1 0]; z_correct = [4 3 2 1 0 1 2 3 4]; assert(isequal(lastzerorow(a),z_correct))

q = 4 q = 3 q = 2 q = 1 q = 0×1 empty double column vector q = 1 q = 2 q = 3 q = 4 z = 4 3 2 1 0 1 2 3 4

### Community Treasure Hunt

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

Start Hunting!