CT48420

Parth and the Peak per Window

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Parth inherited the ropewalk at the willow walks of Reedmarsh along with its curious bookkeeping system for registers. Time to make sense of it. Task: For every contiguous window of length k, print the maximum. Input format: First line: n and k. Second line: n integers. Output format: Print n-k+1 maxima space-separated. Constraints: 1 <= k <= n <= 4000; -10^9 <= a[i] <= 10^9.

Example 1:

Input: 3655 648 535124237 300819662 86597098 379947080 -500354487 537564734 340699626 439381109 787630206 -471782810 -920462231 863760859 875872160 240141770 -330155591 -87811218 293510486 -499021229 392661325 733175726 490363441 676468652 544314431 649237083 -12971415 654790934 155392181 -479508935 194877244 833486418 464756070 29918594 12230726 -63788788 928562325 -331771303 250610368 -354772624 -77497064 382632663 -26242140 312908879 -802838371 327264728 -158106820 187585379 -467820925 217039610 135319537 -472425813 -706072138 210072245 702931892 -360314418 691912137 -297513611 -468049159 -194483018 -511200258 317826411 -996491094 986896890 325653041 -372908156 674654580 899024489 -999386974 -802731446 -822377333 -369100377 405892389 140110273 -737621407 -375944135 -5685372 -253615696 -8164102…
Output: 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 996587813 …

Example 2:

Input: 3445 1799 225847088 -231199130 -779520380 -26974847 512778811 -46668901 557907587 -250032013 105936418 58840763 -802793984 335174542 457223889 597834371 962765895 166170085 -362653847 -806133015 411058613 880880632 -181809440 -779794450 470111407 -199871970 58560587 44680338 22616774 985364357 995764293 279975017 631373982 -313250199 579061116 -927920091 752547288 66797840 -686451399 -718115005 382514855 -267153447 730118071 311374767 892116060 -341250508 -983212378 -691227985 -421623889 -919964210 -802824265 231736296 -597739100 -691720883 844989844 880887621 -414083191 20640402 465575310 114105200 555860384 957542202 -179260283 -561798788 -822233149 -266605391 585806250 -205850828 -8553219 737940501 -174770298 610921917 -949839398 -17098498 134018780 -375012880 -940772411 658684260 -8924…
Output: 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 999084243 …

Example 3:

Input: 809 83 -912988330 991986421 539696766 59358539 -992094594 -20047146 51166230 -868723645 -211251218 -127920523 505705066 173069877 691231814 657970471 -790157424 -601742259 -491884975 -356438604 486961079 -841971607 828542923 333301366 155534265 -707342067 706437358 -748633988 178104251 -146183706 255514144 319773631 346004409 850051227 932846843 -170622225 129636798 750595542 -281806582 -844214891 377123960 486410556 -306830213 503110523 263883672 -608658950 540697130 -133446044 389799227 915399108 422611659 -656078231 -404786273 490879502 -400983944 640088119 -437450389 -129931682 -502063172 -346840914 -951858017 917373897 448201525 677709582 -891656419 747364468 -323275305 941708780 363070311 343842379 -932287407 161473850 473690066 -738714296 -623720696 -951259626 -34728818 -179854693 -…
Output: 991986421 991986421 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 941708780 956121703 956121703 956121703 958315268 958315268 958315268 958315268 958315268 958315268 958315268 958315268 958315268 958315268 958315268 958315268 984494010 984494010 984494010 984494010 984494010 984494010 984494010 984494010 984494010 984494010 984494010 984494010 984494010 984494010 984494010 984494010 984494010 …

Constraints:

1 <= k <= n <= 4000; -10^9 <= a[i] <= 10^9.

Loading...
Test Cases:No test cases
No test cases available.
Parth and the Peak per Window - MEDIUM Coding Problem | CodeTikki