CT32640

Brevin and the Saffron scrolls

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Brevin runs the timber yard at the cedar groves of Balmcrest. Today the books show a list of scrolls, and the numbers must be worked out before sundown. 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 <= 3527; -1000000 <= a[i] <= 1000.

Example 1:

Input: 1477 -758810 -789774 -425421 -594800 -298530 -466116 -64040 -736558 -742558 -896973 -20379 -309280 -837875 -834819 -217148 -810643 -365075 -577705 -66523 -555927 -929023 -153841 -378687 -256727 -188340 -829951 -425841 -109344 -694848 -377649 -439965 -242269 -219518 -902823 -859296 -947634 -401294 -275920 -236248 -680203 -294448 -838517 -899557 -881855 -384052 -667204 -325466 -281443 -155426 -719336 -924962 -604307 -629935 -948507 -936226 -303898 -649973 -223893 -840738 -137479 -780028 -629508 -863736 -715568 -296029 -448590 -629431 -539703 -56992 -266178 -441193 -709463 -509521 -791603 -597905 -249740 -102023 -905436 -836235 -982692 -302262 -110109 -786520 -569592 -855554 -49618 -716619 -387256 -533262 -781951 -406986 -101290 -866120 -212064 -566536 -319591 -11638 -633363 -580276 -290956 -…
Output: 1477

Example 2:

Input: 1962 -85191 -38972 -819977 -612957 -219680 -340195 -574693 -552106 -775846 -844821 -748674 -141923 -377302 -173638 -961552 -915227 -272295 -114831 -646448 -386457 -960616 -363471 -425975 -949897 -402904 -182983 -879301 -739734 -230837 -818870 -588255 -142929 -173738 -828684 -787211 -537672 -320456 -962598 -385344 -986041 -80396 -932069 -822386 -168732 -47388 -101114 -528382 -662147 -405035 -380518 -243640 -787787 -195985 -999467 -506682 -711614 -585525 -166116 -284490 -313318 -621266 -435812 -276978 -328317 -160876 -953935 -869827 -222711 -709891 -707998 -884922 -709312 -602444 -350793 -961124 -504414 -641393 -834815 -801863 -153123 -797095 -876899 -783938 -804101 -483210 -312469 -656820 -227033 -19159 -489442 -153067 -511775 -684294 -899823 -126027 -170036 -459008 -769852 -909527 -585629 …
Output: 1962

Example 3:

Input: 2487 -330258 -402353 -403579 -472437 -626541 -758384 -834677 -735322 -838248 -204424 -303432 -406213 -303496 -364983 -847586 -276919 -149018 -33365 -547329 -820484 -386102 -708506 -225033 -316446 -433891 -960062 -800184 -572034 -806193 -583677 -222170 -153218 -849244 -387528 -792057 -845628 -81784 -949379 -481577 -830282 -545106 -802403 -152074 -833455 -715522 -852753 -686364 -696773 -395519 -883741 -122547 -308827 -679565 -914020 -335364 -538111 -971168 -834292 -535629 -937894 -925822 -954246 -838390 -433552 -76627 -137641 -729811 -764259 -861207 -490187 -681484 -672624 -551797 -963205 -780635 -871567 -243380 -346295 -355743 -10012 -906715 -314582 -186174 -327003 -809145 -701793 -597372 -465930 -578709 -110057 -976516 -267136 -867085 -466154 -900310 -909381 -436665 -213470 -203266 -599936…
Output: 2487

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Brevin and the Saffron scrolls - MEDIUM Coding Problem | CodeTikki