CT34644

Lysander and the Lunar segments

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Caravans arrive at the lakeside town of Mirrormere with crates of segments, and Lysander the customs officer must account for every last one. Task: Print the length of the longest contiguous run in which elements alternate even, odd, even, odd, ... Input format: First line: n. Second line: n integers. Output format: Print the maximum parity-alternating run length. Constraints: 1 <= n <= 1517; 1 <= a[i] <= 1000000.

Example 1:

Input: 475 281768 165044 362628 464238 522211 350930 193852 848655 161607 103621 580894 692526 690985 315765 377525 127344 256455 846093 582700 454175 140219 755170 491737 826331 409743 112688 561769 231139 297400 23684 600520 697562 978222 740230 528962 118373 847532 270379 850159 557846 29055 946919 106183 64406 713356 551395 741770 409641 332134 693972 313607 610567 761580 771460 261770 528643 686401 446711 157935 801609 598979 827440 198251 486101 653287 155522 322792 424361 388841 398978 816029 78855 607294 202021 694149 368398 670809 803931 389515 392810 149174 124348 794791 949033 934029 89879 714537 72842 379009 664447 602731 14296 268690 800113 11806 633881 241673 997055 193940 655375 544533 791864 395872 782076 846882 822258 792092 18048 262312 823038 844492 993970 807288 871796 629952 …
Output: 10

Example 2:

Input: 1263 618181 799275 422382 311001 196915 705521 78791 291894 971300 110413 408211 45519 365032 947002 689682 897567 259063 105266 454633 23836 673922 590977 750056 8928 914132 763449 251561 646687 846622 767733 486219 970348 116094 245739 75021 417975 709908 673270 170311 139231 815221 3526 464729 282932 217172 930097 959841 443237 20323 910386 891779 529411 814268 574168 246244 784974 171457 456588 467280 146650 789858 117747 383632 708011 815191 797839 631501 827149 640295 139212 959141 837679 606910 435122 70519 314429 219324 81797 414782 315848 273654 867314 758388 118316 395964 281352 523266 479504 201179 980311 944649 659319 139457 985175 957770 220358 537839 656313 964868 239389 618887 447198 276829 857740 296963 853933 478816 357144 803335 908704 917247 551593 450274 249994 972434 5…
Output: 10

Example 3:

Input: 1411 851671 946576 407348 607087 988827 565502 119272 508236 104971 751780 465350 946203 547801 945958 295489 901797 232792 558936 284966 429025 525242 112742 164884 119284 760715 984625 56978 986717 182014 500822 416199 878862 506469 526467 87703 104755 489279 458871 891659 309107 735243 723669 521311 566700 705692 447861 468565 320730 349542 964455 715248 27928 279422 52969 316402 934290 837268 535028 432763 986844 65101 790189 46727 68380 645289 374289 243960 351232 13991 600857 74067 677173 840041 483152 126974 743389 123703 982638 441268 129385 224689 918839 756722 935503 738430 464529 882571 170299 823716 417294 601293 977683 466353 375633 894351 125306 490291 330786 381292 505164 538198 384302 437187 222121 784363 980405 53758 529727 32274 640057 867741 947135 220235 118458 208445 2…
Output: 11

Constraints:

1 <= n <= 1517; 1 <= a[i] <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
Lysander and the Lunar segments - MEDIUM Coding Problem | CodeTikki