CT38921

The Fixed Window Peak at Petalbrook

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the garden city of Petalbrook, Mason records each windows in a worn leather ledger. The guild wants answers, not guesses. Task: Print the maximum sum of any contiguous subarray of length exactly k. Input format: First line: n and k. Second line: n integers. Output format: Print the maximum window sum. Constraints: 1 <= k <= n <= 3307; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 2348 1431 -29838 -37146 812 -706257 289540 -484805 346259 73809 -34222 -310949 -201775 480420 525254 -59810 -694575 136162 9125 713863 483018 372648 482081 -46122 -79191 743077 679510 27915 702381 474325 305342 508862 503408 547622 -796527 258011 -445931 618602 -868526 -269921 -488201 504905 281507 97448 555732 929179 -879676 968255 950945 -939177 -856366 -334550 -682103 5943 905190 494616 321517 833491 -860879 -44183 173169 -660475 343834 -558528 466043 559006 -54149 10111 708421 -250786 -839137 -66091 -590566 -171506 351334 -46694 718755 -173938 934374 847994 733530 -468529 -931417 -916890 583932 940856 579641 59458 724303 449163 349785 961832 -489276 -55396 -345554 717925 450314 833948 975231 70641 -695614 540350 601791 -935885 975305 -155979 251521 -911731 87829 -293362 -340746 849443 …
Output: 17798039

Example 2:

Input: 520 15 207372 -795417 -358525 -419293 -474551 929328 -633701 327233 -109406 860975 -770522 -211769 495399 559877 113758 764736 821093 -781323 -792312 -912544 -916113 -622936 -848733 -167802 -469888 -186479 545662 798697 -905553 -879033 104694 -158456 775572 108389 -651517 404568 933774 325360 -318660 350345 -318674 13177 289553 628741 962140 -929123 263620 -695889 461371 -305095 -445055 121178 421820 -175615 653978 -570220 -715044 -93548 551612 82884 950668 -846020 145975 365891 -292366 -503564 -154639 -464140 -798067 397896 814598 -265236 796572 -724758 -313371 966819 129525 -771580 564216 -37715 222574 -856839 27630 -827767 -218437 -397908 -519179 -856081 -413827 -219772 566284 334644 938217 754020 -111220 -869863 63092 -642448 239666 -346354 -943645 465375 -985882 351108 -259575 -909922…
Output: 9026480

Example 3:

Input: 2103 847 -791764 495309 91482 -657674 -401789 -230337 943147 -27520 19479 624100 -86930 -756914 155243 54392 349871 -717703 932115 485096 -392986 -462526 -723476 679353 -993356 928440 384890 628998 968907 142037 -145995 -460356 995340 500585 -891842 929035 -304935 866704 -756913 181571 154202 -527776 225619 398204 259817 154497 151062 -86115 -838380 745622 113162 -672378 585057 676560 91434 18602 -286392 149089 986904 122118 -41568 13179 432599 -15315 -854479 58769 656327 625399 172626 -904447 549325 -914557 56368 -206183 -273577 284105 953337 378403 -206516 -104545 -390705 -833145 -228392 -98717 -179309 -490521 436878 77621 -418938 742595 -852171 -847494 -477488 -751694 979595 787685 656527 709644 896160 -323333 -568333 638073 523471 171911 -67507 88535 518208 878633 176245 -972947 282309…
Output: 36749538

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Fixed Window Peak at Petalbrook - MEDIUM Coding Problem | CodeTikki