CT29449

The panels Zigzag Stretch Puzzle

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Isha found an old ledger of panels in the cooperage attic at the river town of Willowford. The margin notes pose a precise question. 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 <= 3941; -1000000 <= a[i] <= 1000.

Example 1:

Input: 234 -417634 -397566 -33544 -403823 -2284 -324145 -995819 -291976 -94976 -226827 -587423 -145098 -324716 -717901 -134982 -230412 -900496 -816991 -592139 -773838 -505479 -498652 -424814 -794223 -704590 -618390 -93247 -528971 -434083 -393924 -964629 -312432 -569130 -885359 -329681 -709319 -349731 -234545 -345369 -776290 -323185 -96070 -384806 -582702 -320546 -676285 -810558 -573519 -155187 -624802 -871467 -765761 -583765 -506173 -542250 -596727 -688297 -544743 -965002 -912421 -350384 -797511 -73203 -809851 -366745 -458104 -360149 -324811 -174027 -338656 -198356 -997059 -343663 -67357 -751713 -514388 -563717 -917665 -677742 -314814 -297734 -268833 -362414 -903600 -169755 -320818 -107050 -670759 -76421 -626826 -387456 -815437 -163703 -109565 -737572 -884123 -853157 -294800 -670465 -143590 -4935…
Output: 234

Example 2:

Input: 2229 -639502 -553623 -448562 -566210 -785263 -551398 -451900 -344567 -223688 -738555 -665450 -531735 -569324 -378222 -445542 -387685 -678127 -93084 -474243 -843499 -269130 -199237 -410471 -977714 -966131 -214610 -232793 -583807 -970927 -827628 -831943 -829568 -115133 -247825 -841628 -957764 -634676 -849095 -620634 -107336 -569389 -97214 -196454 -12030 -473065 -229081 -54513 -700164 -111618 -424375 -12139 -744470 -155833 -511686 -594794 -965415 -136731 -56004 -904811 -322224 -644942 -899020 -728194 -215442 -553920 -495910 -834182 -46059 -86062 -273485 -715946 -529407 -497550 -30979 -559759 -699688 -917376 -538369 -694389 -998359 -737352 -520082 -776662 -960364 -623621 -886725 -236420 -326161 -68622 -720677 -466137 -142963 -411587 -879236 -936673 -435768 -128609 -772456 -687948 -322123 -6950…
Output: 2229

Example 3:

Input: 2085 -96979 -879706 -629195 -744801 -301140 -962661 -761647 -666033 -173643 -345880 -516904 -17078 -151996 -861716 -323107 -168659 -641379 -639230 -951924 -494537 -402845 -567753 -53888 -596556 -365583 -129409 -543363 -843592 -91648 -270923 -423729 -396831 -70010 -263377 -845640 -291445 -667540 -858732 -197367 -533409 -193483 -256983 -272710 -722765 -369222 -949855 -333046 -854373 -514591 -226181 -981136 -293975 -781636 -99885 -133488 -836584 -609619 -730254 -366185 -728926 -498441 -428129 -50251 -965701 -673870 -876125 -366013 -896078 -57970 -647897 -948246 -991934 -876286 -796376 -615300 -158303 -296440 -861284 -989086 -781685 -441983 -95046 -374193 -486594 -173536 -636933 -25509 -503743 -880488 -862899 -836326 -350001 -713974 -736542 -335822 -99541 -248180 -526863 -171789 -588108 -73355…
Output: 2085

Constraints:

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

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