2,1,7,3 that’s the case uh suggested for not applying greedy, but while choosing the opponent’s no. uh are choosing the maximum one for him, what about the greedy exception for opponent here?
Why greedy exception for opponent is not considred here?
Greedy is not being applied for the opponent.
Both plays optimally.
So on Player 1’s chance , he will pick such an element such that the maximum points attained by Player 2 after this turn is minimized.
Similarly on the next call ie. on Player 2’s chance, he will pick such an element such that the maximum points attained by Player 1 after this turn is minimized.
so getting the other’s points minimized one must have to pick the maximum no. for himself always??
It is not necessary that the current player picks the maximum element. If you just pick the maximum element then it will be called a greedy solution.
Say the array is
2 1 7 3
If you always pick the maximum element (Say player 1 starts the game)
Player 1 picks 3
Player 2 picks 7
Player 1 picks 2
Player 2 picks 1
So Player 1 score: 5 and Player 2 score : 8
So player 1 was not able to win by applying greedy.
But player 1 can win the game if he start by picking 2.
So dry run this case with the dp solution provided in the video and see how it actually works
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.