CT31197

Wheelwright and the Checker Stretch

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

It is audit day at the silver mines of Lodebarrow. Wheelwright spreads the segments records across the table and picks up a sharp pencil. Task: Print the length of the longest contiguous run in which elements alternate even, odd, even, odd, ... Input format: First line: n. Second line: n integers. Output format: Print the maximum parity-alternating run length. Constraints: 1 <= n <= 2827; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 19 464883 433691 704808 -978463 252703 -499494 -584088 -62186 781257 757024 -855783 -685523 988295 720171 -916982 758220 218734 487980 775379
Output: 4

Example 2:

Input: 528 963521 436037 797668 348230 222299 -488492 179323 12159 -472462 26184 67760 -156589 729963 -511689 -539584 -310154 521482 -23877 257072 -877072 -726102 835586 521460 335733 -453315 -650888 27263 -486164 692436 314278 159053 771969 -528828 -326384 -633609 -550824 560416 27727 775667 774229 -112699 -418096 324799 -41667 -174751 -194141 -532406 -737468 985405 803426 -896778 124646 -682704 509834 361882 -604017 982132 282103 337941 538308 -93086 362461 846847 -785876 404057 -425537 597336 -82244 354070 312987 825244 907675 120895 289120 855704 -989446 656434 -740512 407777 754893 7860 257116 184260 353341 -238409 -69225 354469 200647 306504 394562 807113 -594617 -790790 -651912 171059 817831 608595 440030 910445 -97951 -887972 734989 361555 -792921 -169509 522953 86778 -158618 -62508 62827…
Output: 9

Example 3:

Input: 778 447062 391197 51010 -861279 875628 -834318 -792022 -20403 -274276 -345360 -116698 615819 -425207 591213 -700046 80182 703972 -823789 -436912 -466295 -149143 -785803 -304523 -368282 -859483 949993 -294212 783087 -937345 -270469 -78251 650398 -596572 -587086 -143374 122630 730045 -782561 -270703 755546 -618938 465094 959825 -775810 107376 -440764 869948 -415742 -299914 -675884 -315977 -407763 -656552 -472030 -614931 401576 -513300 913517 423156 -277354 802321 -416593 -854639 -955544 627461 52007 -773070 -635488 -720133 -859872 -610226 -786928 983852 621262 358159 -551714 -288673 -509432 824066 508653 -315525 -388300 54726 6519 -908040 658629 -857115 798162 301174 433608 396638 863380 -460882 77214 -497474 -449535 -868819 -55500 -670183 361263 686777 -486757 -513319 15546 -553758 -631194 …
Output: 8

Constraints:

1 <= n <= 2827; -1000000 <= a[i] <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
Wheelwright and the Checker Stretch - MEDIUM Coding Problem | CodeTikki