CT31247

The Zigzag Zigzag Stretch

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

At the copper works of Verdigris, Kavya records each scrolls 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 <= 1495; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 948 -458373 -585395 -811945 -593707 -888695 -537944 -606227 -568724 -244391 -285531 -776969 -992282 -141143 -201335 -358675 -757 -566674 -913327 -12847 -71240 -402471 -226943 -93315 -263901 -255505 -307794 -727007 -59692 -35574 -226474 -472810 -603039 -473395 -508033 -617104 -824722 -103115 -562777 -744727 -437146 -867232 -234584 -231575 -276443 -744462 -326785 -518932 -592465 -90775 -861933 -305126 -794393 -427108 -213726 -792468 -671195 -996143 -603629 -735303 -115001 -447530 -397814 -829049 -721123 -755177 -115483 -726239 -904256 -385927 -586956 -888473 -598152 -188803 -420956 -197420 -940027 -122732 -584395 -237224 -444790 -849992 -953150 -408696 -307374 -597076 -251977 -372005 -407984 -959472 -479501 -710677 -801406 -598808 -540610 -204350 -757273 -840220 -114093 -247797 -56132 -50500…
Output: 948

Example 2:

Input: 35 -309038 -283449 -733549 -685859 -458870 -992122 -743578 -125037 -143557 -471379 -155650 -246322 -631840 -553276 -997202 -505340 -550448 -555256 -828718 -236098 -856955 -256386 -478962 -971756 -226540 -375602 -728999 -953828 -889386 -568455 -946652 -900328 -369780 -436299 -834377
Output: 35

Example 3:

Input: 1015 -301032 -724174 -720060 -554398 -896365 -259543 -538007 -53809 -45096 -624436 -557648 -936213 -592757 -11454 -450625 -15842 -249378 -896017 -921190 -941081 -120087 -464930 -330479 -450590 -596438 -463345 -741939 -198110 -561445 -552800 -901332 -173314 -924073 -153495 -101871 -608933 -177852 -941715 -458968 -150161 -281738 -6448 -913979 -225068 -380294 -637471 -495508 -162924 -651931 -604830 -786893 -71987 -296629 -105458 -17791 -328045 -259322 -112405 -748523 -416268 -961065 -1028 -578121 -53299 -800518 -739109 -224731 -254007 -462887 -598299 -839284 -214943 -302897 -410619 -126127 -849643 -602816 -483478 -886614 -245376 -426306 -816804 -492305 -671301 -592921 -576354 -342031 -397551 -138339 -829774 -8498 -287574 -763047 -260908 -725971 -233194 -972251 -81701 -271988 -525565 -858229 -…
Output: 1015

Constraints:

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

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