you give 0indexed integer array num represent content pile nums0 topmost element pileIn perform followingIf pile remove topmost element pileif remove element add pile this element new topmost elementyou give integer k denote total number move madereturn maximum value topmost element pile possible exactly k move in case possible obtain nonempty pile k move return 1 example 1input num 522406 k 4Output 5explanationone way end 5 pile 4 move follow step 1 Remove topmost element 5 the pile 22406 Step 2 Remove topmost element 2 the pile 2406 step 3 Remove topmost element 2 the pile 406 step 4 add 5 pile the pile 5406note way end 5 pile it show 5 large answer possible 4 movesexample 2input num 2 k 1output 1explanation in option pop topmost element pilesince possible obtain nonempty pile return 1 Constraints1 numslength 1050 numsi k 109