CT32239

The Zigzag Checker Stretch

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

It is audit day at the mining town of Ironvein. Tanya spreads the scrolls 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 <= 1443; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 399 -21228 355490 -979621 -436902 591475 204597 -500971 -898841 440469 319376 -551594 -618691 357978 579935 -695498 -499112 502140 -778273 -601305 339393 823882 574953 60205 646724 -921377 552502 450119 334944 -977351 911765 942443 631047 -577732 -964152 -491919 109605 -998210 243399 333366 -946759 -43011 -937271 -274383 -800391 501640 -643170 -132135 -908629 -301141 -92807 -928165 -377295 611795 -455137 332637 -84999 544422 -796637 948115 674837 -111648 25214 -186227 -573633 723020 -206576 -11107 -630010 -631848 273970 161475 996887 -997944 -835415 707090 -958286 -523281 -731212 -889469 416128 650078 -162034 -650124 99429 -316149 -877682 -943147 749804 100385 -195843 -827846 -219101 -624224 594 -227579 -667284 -291651 -303524 756174 -437291 695038 449852 227949 -666265 687221 593020 -6375…
Output: 7

Example 2:

Input: 8 -851888 -700972 900376 -568808 -848977 90118 -183265 -623468
Output: 5

Example 3:

Input: 268 716353 35280 862041 -88870 945142 344846 993121 28313 743446 598024 -263258 -774504 550929 960279 -446417 -478988 301358 -177735 543305 -995289 702054 154019 296530 302136 -335189 -610685 -308202 -129687 93956 -772399 487001 -514935 -210358 -313434 -633699 -68093 -253992 320714 -270584 830432 -802112 542165 -614596 655192 -462016 -320848 -94558 978933 160066 -77819 -654764 -930776 724845 -447531 -8125 -617525 -491475 -476058 -639773 -475165 422681 381190 444280 -156041 -476770 -617871 -197140 355094 102464 -864172 206834 917034 -765566 23306 240839 -869979 -719060 418456 -750659 -848424 -650335 -633968 -221477 958495 -988355 -440309 -396 245424 501074 315751 -376390 -302055 -867004 46597 669865 317602 716694 -684973 892521 -450482 240038 618452 -413433 -564308 981576 513383 -379703 923…
Output: 8

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Zigzag Checker Stretch - MEDIUM Coding Problem | CodeTikki