Earlier I was trying to solve this using recursion, but getting timelimit exceed in it, thanks for the solution, this one worked for me and the code is easy to read also.
@nikoo2810 ай бұрын
I usually avoid recursion. It is so hard to understand and debug 😅
@ANJALIGUPTA-vq1cv2 жыл бұрын
i thought the same greedy approach and after unlocking the test case i get to know what im doing wrong.Thanks for the perfect explanation
@nikoo282 жыл бұрын
You are most welcome :)
@lautaroblasco Жыл бұрын
Great video man, it really helped me to understand the problem.
@b994423611 ай бұрын
Nice explanation, thanks.
@miomydude2 жыл бұрын
Very clear thought and explanation. Thank you very much.
@jjoelthomas10 ай бұрын
Amazing work. Keep it up!
@rishabmudliar5583 жыл бұрын
Thanks for explaining the approach. Could you do a DP approach? I initially tried it out but I got timeout error and then applied memoization but then my solution got weird so I came to your video. Thanks anyways:)
@ahadkhan66302 жыл бұрын
Thank you so much ... We made the solution clear but as I can see this solution actually violates the functions of the stack you can see that in the second loop, there must be some other solution
@nikoo282 жыл бұрын
What function of the stack feels violated to you? I can try to clarify.
@pranavdeshpande6385 Жыл бұрын
Great explaination!
@SomanathMikali-f7f8 ай бұрын
37:27 That Game of two stacks is failing for the large number of inputs, getting time exceed error, is it probably that we use recursion huge number of times?
@doubtee154283 жыл бұрын
Sir if maximum sum is 10 instead of 11 then according to your logic it requires 3 element from stack 1 But answer is same 4
@nikoo283 жыл бұрын
Try doing a dry run of the code with your input arguments. The logic I provided will check for all combinations, you will always check for elements from second stack
@shubhadarajmane73233 жыл бұрын
Could you please explain Time and Space Complexity of efficient approach that you have used?
@nikoo283 жыл бұрын
The time complexity would be O(m + n) where 'm' and 'n' are the length of two stacks. That is because it might be possible you have to iterate through all elements of both the stacks for a very large maxSum. The space complexity would be O(1), as you are not consuming any extra space.
@shubhadarajmane73233 жыл бұрын
Ok...Thanks
@dineshkinibailoor34010 ай бұрын
@@nikoo28 arent you running while inside second for loop? so it should be n^2 right?
@gauravgupta18032 жыл бұрын
Thank you so much 💘
@ANJALIGUPTA-vq1cv2 жыл бұрын
thank you sir
@siddhantjagdish25542 жыл бұрын
Thank you!
@nikoo282 жыл бұрын
Always welcome
@sreepadhsandilya58542 жыл бұрын
very helpful....thank you..
@nikoo282 жыл бұрын
You're welcome!
@ramkrishnainmotion3 жыл бұрын
can we use dynamic programming ?
@pranavmishra55163 жыл бұрын
sir do u take any classes
@nikoo283 жыл бұрын
not yet...but can plan it sometime in the future.
@saarthjhaveri87163 жыл бұрын
whats the logic behind this?
@nikoo283 жыл бұрын
Think like this, “you only need to use additional elements if using them will increase the number of elements used” So, the general idea is to use one full stack first. Now, try to use the second stack. Remove one element at a time from the first stack and try including elements from second stack.
@HarshitSharma-kk6yz3 жыл бұрын
Hello
@ramkrishnainmotion3 жыл бұрын
3 5 105 100 4 2 6 6 6 6 6 please explain this example...! ig we have to do in perspective of both stack then return the maximum one