CT32833

Last ribbons of Trader

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Caravans arrive at the ember mines of Cindercrag with crates of ribbons, and Trader the clerk must account for every last one. 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 <= 2418; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 162 -238574 -364833 -556889 -902569 -338650 -978677 -809299 -306041 -882370 -333456 -63532 -996274 -106042 -911907 -938824 -683278 -24270 -244049 -825867 -480875 -732192 -57492 -891959 -434826 -32623 -33340 -61183 -528213 -889541 -287868 -573085 -328293 -897935 -785261 -898035 -242220 -590543 -413323 -452399 -838956 -557827 -373085 -676118 -970678 -938293 -250405 -12578 -922043 -647688 -397003 -754300 -134830 -645711 -512392 -397094 -448841 -294001 -312159 -747274 -342967 -973160 -268998 -130377 -364983 -390332 -42479 -791365 -849376 -210839 -95484 -147451 -928697 -104211 -827411 -69930 -653574 -314747 -207618 -569803 -475646 -864423 -931986 -421019 -64486 -521775 -694665 -512107 -203987 -377069 -528791 -921960 -9978 -886223 -25699 -197894 -890268 -584259 -891007 -390749 -787299 -555966 -6…
Output: 162

Example 2:

Input: 2032 -410309 -358836 -179426 -147382 -176747 -808559 -806929 -759806 -16235 -603231 -566520 -425686 -727549 -409055 -473318 -580459 -330534 -871129 -903964 -468423 -265838 -859159 -656705 -626835 -143839 -463154 -463518 -581438 -144665 -914344 -719283 -877839 -899842 -520347 -669722 -739403 -948707 -150798 -388932 -686391 -581916 -854817 -753777 -274325 -698429 -204804 -933587 -769768 -331906 -196351 -43753 -54026 -808041 -869771 -933059 -612860 -180750 -573194 -623023 -391561 -313758 -134677 -234581 -433028 -812005 -603918 -313303 -985481 -7862 -798270 -689827 -582 -588836 -187791 -567283 -757811 -717516 -972348 -418223 -782026 -248989 -118268 -717510 -815503 -855512 -119071 -119859 -817047 -672338 -460390 -90735 -856183 -65213 -35209 -949349 -604587 -183813 -929138 -912552 -388361 -63314…
Output: 2032

Example 3:

Input: 1748 -39603 -12503 -356925 -303158 -819335 -241855 -638958 -60332 -479554 -602690 -486852 -873101 -185231 -266224 -21228 -649784 -710733 -942396 -433992 -798069 -910458 -568988 -719948 -928816 -920204 -845384 -839629 -404534 -466604 -581380 -926273 -480974 -707506 -684809 -670445 -760615 -228147 -28418 -956490 -309757 -425839 -758975 -538146 -110880 -27219 -805679 -347445 -970032 -466551 -30945 -233508 -703261 -523524 -916859 -130687 -994987 -401059 -831274 -486038 -625942 -981782 -297911 -948985 -474018 -495235 -25489 -184446 -128430 -3566 -536344 -973796 -731995 -328078 -609765 -89710 -284142 -527312 -160876 -88959 -761948 -660119 -39084 -100288 -151387 -576909 -807113 -201600 -592162 -697205 -182362 -855270 -469886 -337154 -357514 -40745 -965150 -456866 -736620 -819568 -959608 -537109 -…
Output: 1748

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Last ribbons of Trader - MEDIUM Coding Problem | CodeTikki