CT34996

The Longest Chain Beneath Ashfall

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Envoy runs the brewery at the ember dunes of Ashfall. Today the books show a list of shelves, and the numbers must be worked out before sundown. Task: Print the length of the longest run of consecutive integers present in the array (e.g. 4,5,6 counts as 3). Input format: First line: n. Second line: n integers. Output format: Print the longest consecutive run length. Constraints: 1 <= n <= 5660; -1000000 <= a[i],x <= 1000000.

Example 1:

Input: 5065 -848679 -852488 656527 -671532 238657 943191 -643726 -870413 695585 459254 340265 235048 -350388 239675 -993472 -661687 769850 -633927 779232 160356 -988221 594046 192864 -685059 -234950 958869 -103165 -65541 109106 -443943 372084 -767692 771551 -374553 918374 -546687 173043 785753 728659 -55986 -9553 913204 741998 -847521 361533 361438 -949612 -373341 747521 -626147 29075 77933 273925 -61759 724053 -390760 -17798 -325866 363501 -568619 357418 -368249 -350936 111988 109090 976814 733024 233904 622171 -285464 751007 -631452 -733763 -939190 -469844 327620 -376184 744213 -940591 -454270 -739454 -23484 -228552 -429169 -513812 -845610 -518518 600917 -76708 473365 406114 583908 -403843 382136 -922043 -252109 -975204 737221 -542608 666388 -949354 -111949 -654923 688310 -580138 714113 -444008…
Output: 2

Example 2:

Input: 1515 -500719 -340357 133200 -39544 950110 457564 658378 -877466 -766556 331283 294890 -534622 -778287 -774924 451617 -188676 -558814 189199 -342827 494702 -486301 -199876 289851 -963182 648442 -224670 903654 -469845 320043 -128310 883103 217649 992207 994694 823145 -411615 541233 384540 -609195 648945 466712 312500 100464 -322071 -239406 49975 530984 412848 -467278 -374287 921790 -430324 -604314 776530 928592 -950458 -870866 641848 -660075 -272332 132286 458731 91661 98948 432843 260292 171070 923895 916281 531895 -688381 632654 -748007 -62111 639300 800634 -378639 56784 -376933 167704 -63311 -303670 -410691 397227 -617801 -2962 20223 -963563 -382047 624293 -148925 340902 -425681 -228262 -745831 324609 681136 682095 -36274 967319 -395060 646937 -885122 50940 -278049 639879 121516 428061 -6…
Output: 1

Example 3:

Input: 4084 -260866 589706 -320289 -79763 681291 689755 -527376 581417 535243 599362 473164 827170 -299368 -843614 90947 -164611 79338 -321265 613703 -844171 323199 -694184 385663 730782 -876237 -773974 -284673 614357 603318 383050 -821690 62588 -761660 -813448 621472 -989862 -283140 -984376 -972002 -389896 -840129 12520 -704245 -586408 -187232 -263835 -858290 -455853 -252715 -624547 821618 -969139 532023 -714729 715253 -740609 -907995 539390 -789332 504514 -954660 -413983 279600 459677 239423 -467598 -993556 -503944 -239274 -490931 586217 -853365 -131838 -614090 -767593 945934 -461448 731671 -310050 511338 983701 944446 982083 790238 932156 819118 960103 890799 416400 -137181 -368987 10536 99135 778033 940513 246383 -697565 -383163 992056 -354398 587643 538820 -676661 788450 -927111 -353002 6737…
Output: 2

Constraints:

1 <= n <= 5660; -1000000 <= a[i],x <= 1000000.

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