We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Giving chocolate to everyone except the chosen person is the same as taking chocolate away from the chosen person. We don't care about how much chocolate they end up with, only that each person's amount is equal.
For example:
Give 5:
1 3 5
6 8 5 <-
Take 5:
1 3 5
1 3 0 <-
The two results are the same relative to themselves, just shifted:
1 3 0
+ 5 5 5
---------
6 8 5
The problem becomes much simpler now.
Also remember to look for caching opportunities.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Equal
You are viewing a single comment's thread. Return to all comments →
SPOILER! Hint if you're stuck:
Giving chocolate to everyone except the chosen person is the same as taking chocolate away from the chosen person. We don't care about how much chocolate they end up with, only that each person's amount is equal.
For example:
The problem becomes much simpler now.
Also remember to look for caching opportunities.