CT32610

Archivist's Golden segments

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

At the singing sands of Echo Dunes, Archivist records each segments in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1942; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 8 900958 -108928 -294974 902026 -738014 541145 -671141 -729592
Output: 2

Example 2:

Input: 16 817481 -130559 558221 780596 -859042 559814 107649 -485858 118632 -251712 -691557 -751514 -163233 365176 -917364 -846997
Output: 5

Example 3:

Input: 1280 788795 -643259 -488823 -810937 38448 -923522 537556 -100631 -548781 266811 190288 -1829 625271 877511 -510818 130295 -702157 -195088 -827237 -238785 -429269 695629 357179 -786987 697958 169383 846637 -103893 270030 845320 -592864 732882 -159916 -292564 -853286 -160805 -652907 -593831 -319927 367651 895188 -254972 353509 -146005 561785 -138513 -520377 737095 -136019 148840 817169 -109113 -603068 -192128 -861192 610203 -986358 -170878 979239 580386 -507789 -374686 701767 -354721 -982285 -767360 89333 -944027 -80968 -305922 -938941 -488619 -885472 -112470 847806 -696136 -918288 -460628 -750613 -330067 150417 -728112 915386 -98110 -216275 -610235 668052 -400240 -254219 537292 -562439 -630222 -376087 681980 -750502 -13643 -835526 -72322 296223 -585850 794406 -139756 -411015 -269121 -186607…
Output: 9

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Archivist's Golden segments - MEDIUM Coding Problem | CodeTikki