CT54507

The Fixed Window Peak of Tidewater

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the coastal hub of Tidewater as Lothar unrolls the day's manifest of panels. The tally will decide the next shipment. 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 <= 2189; -1000000 <= a[i] <= 1000.

Example 1:

Input: 1230 407 -92045 -978428 -246122 -518406 -421283 -126617 -68153 -336925 -901415 -789554 -603603 -165385 -678818 -843968 -670104 -105383 -213834 -461487 -242942 -271574 -145528 -316928 -634992 -888492 -37616 -994148 -754808 -897568 -721854 -882341 -22254 -138219 -510017 -253676 -553245 -608024 -550493 -548468 -730184 -293868 -908911 -502037 -572978 -331672 -473169 -917107 -838799 -995477 -191461 -379835 -514966 -321548 -251327 -755369 -962973 -378623 -781943 -835212 -528041 -806907 -261577 -216455 -618132 -350284 -446957 -103950 -173451 -521199 -244371 -814558 -468223 -405304 -547547 -56726 -133910 -855655 -808830 -51722 -334180 -718493 -438572 -321670 -601637 -243590 -924368 -537218 -718441 -819668 -41760 -743914 -927692 -242446 -167502 -28862 -404698 -884535 -258509 -766107 -833859 -901800…
Output: -193108702

Example 2:

Input: 917 415 -61852 -64706 -217023 -669622 -28920 -982016 -702131 -949728 -278817 -48492 -304822 -228600 -388266 -201809 -820108 -523215 -185402 -268722 -16044 -847029 -172375 -442521 -855679 -370490 -593038 -608012 -273691 -569495 -645629 -158734 -186289 -836394 -74190 -167299 -996681 -391943 -993719 -628010 -487754 -269562 -138702 -344871 -512681 -709280 -377028 -671067 -183796 -743180 -594319 -318938 -323019 -486736 -652799 -618542 -784717 -150173 -51389 -497793 -589293 -884926 -77894 -555532 -192416 -144705 -184531 -946437 -193659 -34619 -100061 -783400 -317118 -13108 -3563 -615608 -824117 -163143 -822628 -327499 -918632 -69629 -450791 -888637 -931218 -138855 -934805 -363541 -273066 -587197 -120932 -641958 -330749 -335102 -541089 -549475 -702560 -610064 -547657 -242776 -124021 -93326 -96014…
Output: -203693599

Example 3:

Input: 510 414 -831380 -296518 -704707 -370903 -322742 -272747 -792890 -334622 -973178 -734655 -412183 -715067 -596352 -788715 -994155 -156361 -535872 -521897 -336089 -629569 -151847 -656427 -413664 -481547 -94410 -420912 -764495 -624515 -268693 -671668 -635270 -81847 -116477 -259569 -991035 -835609 -437345 -104478 -86683 -983344 -625051 -186290 -627486 -223067 -799378 -569212 -638702 -194627 -788305 -595574 -682403 -181454 -252438 -286154 -149236 -874649 -821520 -741112 -493629 -466562 -208646 -223359 -728554 -221124 -133019 -124575 -112304 -947928 -841676 -563534 -509844 -323599 -430576 -504507 -853782 -483458 -424644 -281351 -584477 -77373 -482242 -825327 -524180 -648128 -443590 -626838 -111298 -35538 -218710 -878246 -349528 -284582 -209974 -431842 -890981 -877389 -973596 -611562 -580331 -5929…
Output: -203959817

Constraints:

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

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