CT31266

Ivan's Ledger of stretches

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Ivan inherited the cellar at the mushroom groves of Fungaldeep along with its curious bookkeeping system for stretches. Time to make sense of it. 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 <= 3183; -1000000 <= a[i] <= 1000.

Example 1:

Input: 1711 -496629 -365954 -489236 -612845 -589882 -268708 -19275 -516785 -933523 -748938 -999404 -269577 -14055 -422922 -643492 -867484 -545137 -167190 -780257 -420851 -389027 -30890 -111023 -814489 -516012 -974130 -734209 -69621 -373654 -425053 -358084 -318796 -525660 -318681 -818171 -457429 -372148 -346148 -912997 -951897 -176860 -873735 -445291 -738812 -340128 -568688 -117655 -98776 -699952 -367170 -569477 -878634 -313136 -624286 -289240 -654088 -853325 -282442 -934141 -994758 -673892 -271016 -340371 -962123 -857886 -649918 -312310 -547990 -251252 -422982 -461943 -696980 -10126 -154965 -788310 -34996 -29256 -953150 -5052 -522628 -300374 -491331 -961145 -559437 -916800 -938893 -879702 -574987 -67068 -652542 -77193 -538310 -445293 -714754 -628952 -939292 -475505 -442799 -611489 -496081 -866416…
Output: 1711

Example 2:

Input: 2932 -271634 -237152 -290841 -552744 -915601 -52014 -121139 -130539 -395533 -878208 -805680 -581602 -598830 -185788 -446713 -431199 -345160 -34516 -500391 -280531 -51596 -210094 -531126 -451471 -614676 -219361 -224975 -69727 -987403 -915367 -997143 -15784 -46563 -83707 -295636 -418615 -701059 -414763 -509866 -505867 -192828 -630596 -135880 -809394 -798818 -30436 -367949 -353417 -120485 -543859 -735370 -861404 -320534 -639653 -710300 -380942 -442909 -927979 -78154 -360113 -618216 -747274 -314755 -288122 -780947 -168436 -860949 -627985 -980577 -160481 -451419 -513532 -772500 -404230 -878631 -743989 -807823 -338369 -238816 -861515 -814911 -938730 -293900 -527465 -490078 -951438 -173618 -684919 -296863 -263430 -963306 -193061 -704246 -580864 -517523 -461269 -404206 -52383 -633231 -972343 -3239…
Output: 2932

Example 3:

Input: 276 -112785 -764690 -870175 -824122 -648295 -863604 -557603 -526244 -931438 -236232 -643175 -858555 -491940 -703769 -184351 -984577 -627060 -600629 -592126 -664904 -481502 -889148 -384786 -90019 -200438 -914875 -417047 -70745 -719175 -379334 -810535 -466221 -889067 -568580 -764414 -498699 -798012 -841819 -609433 -48859 -124121 -862933 -535499 -178044 -222317 -439481 -757847 -896226 -631597 -683210 -480847 -416862 -646896 -417463 -210832 -980357 -666994 -544777 -300353 -257748 -828558 -400974 -132707 -975841 -29248 -556436 -713462 -479830 -542923 -25550 -509523 -92359 -617939 -136511 -364066 -309299 -116782 -141984 -65139 -196471 -247544 -549111 -237918 -204604 -640377 -740547 -994019 -635311 -657206 -987305 -507943 -9629 -779202 -541077 -376586 -133952 -385993 -376509 -976672 -21250 -29532…
Output: 276

Constraints:

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

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