HackerRank - Game of Two Stacks | Full solution with visuals | Study Algorithms

preview_player
Показать описание
You are given two stacks and a maximum sum. A score is determined by the maximum number of elements that you can pop such that the total sum is less than the maximum sum. You need to determine the maximum number of elements that you can pop such that the sum remains less than the maximum sum. Watch this video to find an easy solution along a with a dry-run of code.

Chapters:
00:00 - Intro
01:21 - Problem Statement and Description
04:51 - Greedy Approach
07:10 - Why does Greedy fail?
09:36 - Efficient Solution
13:02 - Dry-run of Code
16:29 - Final Thoughts

📚 Links to topics I talk about in the video:

📖 Reference Books:

🎥 My Recording Gear:

💻 Get Social 💻

#hackerrank #programming #interview
Рекомендации по теме
Комментарии
Автор

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.

gilbishkosma
Автор

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

ANJALIGUPTA-vqcv
Автор

The best in your videos is the relatability. I also thought that minimum pick will be right one but almost all test cases failed. It is like watching myself just in a english 😂

NikhilKoshti-fs
Автор

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?

SomanathMikali-ff
Автор

Great video man, it really helped me to understand the problem.

lautaroblasco
Автор

Hey, this was pretty much better than the recursive solution.

NikhilKoshti-fs
Автор

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:)

rishabmudliar
Автор

Very clear thought and explanation. Thank you very much.

miomydude
Автор

Could you please explain Time and Space Complexity of efficient approach that you have used?

shubhadarajmane
Автор

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

doubtee
Автор

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

ahadkhan
Автор

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

ramkrishnainmotion
visit shbcf.ru