CT30767

The Zigzag Stretch of Scrollkeep

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

At the archive halls of Scrollkeep, Mira 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 every two consecutive elements differ. Input format: First line: n. Second line: n integers. Output format: Print the maximum alternating run length. Constraints: 1 <= n <= 1430; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 429 -906795 -4562 -804694 -848093 -864717 -106592 -309633 -111756 -720015 -821032 -593755 -588007 -602635 -880580 -876468 -735009 -890802 -282572 -595581 -648738 -862992 -752663 -432350 -772882 -672611 -724279 -898587 -235043 -492319 -636315 -273894 -925342 -97813 -440470 -584432 -348578 -822352 -83841 -321115 -520353 -532454 -743672 -844772 -421084 -153032 -823015 -730790 -139233 -691728 -212220 -621525 -146602 -454065 -425107 -539372 -418316 -893061 -844598 -355564 -649273 -218510 -276367 -377601 -240226 -468463 -179695 -199883 -175531 -85095 -652678 -768434 -360747 -390244 -113986 -169022 -700990 -429104 -180196 -203553 -537363 -147436 -240999 -220107 -994068 -318659 -117101 -329554 -470832 -271664 -429732 -326840 -144882 -861119 -199955 -55662 -472758 -751342 -666348 -495519 -858112 -1…
Output: 429

Example 2:

Input: 1401 -803943 -45965 -520302 -794585 -323533 -237791 -782154 -637606 -893778 -333218 -505792 -863206 -89355 -324773 -877479 -423755 -460450 -417215 -435928 -966249 -57121 -515439 -778632 -885704 -256146 -569938 -948255 -887381 -641432 -194894 -393047 -823665 -384961 -414437 -231073 -526313 -658531 -721716 -738056 -680136 -715480 -456455 -92238 -690978 -710332 -18853 -10380 -780658 -155456 -556842 -854398 -895037 -355892 -557932 -662043 -453050 -304045 -359512 -241651 -934389 -708893 -425016 -356055 -690807 -37551 -818133 -70856 -839047 -428346 -666837 -736680 -241635 -32850 -349 -723567 -601662 -518402 -594919 -351707 -244229 -795921 -636994 -342308 -420720 -927654 -803420 -688455 -198711 -393177 -58426 -902073 -544043 -33861 -510259 -837458 -981749 -340334 -407760 -656516 -976901 -386735 -…
Output: 1401

Example 3:

Input: 431 -526586 -688432 -957770 -473460 -636655 -973817 -31184 -232810 -710768 -744161 -992242 -682727 -365439 -845838 -181846 -231471 -257753 -938351 -192044 -722838 -284555 -805085 -116822 -755723 -32604 -119857 -567773 -957612 -774996 -37848 -826748 -676111 -87495 -744352 -563627 -427365 -419006 -729925 -154026 -238512 -663831 -990649 -524866 -316445 -60079 -447583 -587099 -124354 -654037 -262227 -892624 -694626 -75432 -262658 -625044 -159956 -125668 -527899 -372075 -736214 -989228 -52600 -9196 -43938 -554051 -614312 -723157 -118135 -783905 -615856 -320330 -704552 -925226 -577594 -292049 -668786 -717662 -153325 -556125 -855646 -262502 -521047 -986609 -409927 -579252 -863352 -270951 -3114 -835613 -976064 -687437 -461428 -449738 -597018 -7605 -854925 -72420 -641536 -258826 -178953 -813367 -50…
Output: 431

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.