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.
Keeping a window of next 3 expected stickers seems to be the best approach, it is optimized, and logic is more clear, readable, and direcly relatable with the question. Though instead of a queue, an array of size 3 will work better, that too without any pointers. Instead of 1 queue-append & 1 queue-pop in each of 3 cases, we will need 3 simple updates (array updates will be done by index) in case of 0 bribes, 2 updates in case of 1 bribe and only 1 update in case of 2 bribes.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
New Year Chaos
You are viewing a single comment's thread. Return to all comments →
Keeping a window of next 3 expected stickers seems to be the best approach, it is optimized, and logic is more clear, readable, and direcly relatable with the question. Though instead of a queue, an array of size 3 will work better, that too without any pointers. Instead of 1 queue-append & 1 queue-pop in each of 3 cases, we will need 3 simple updates (array updates will be done by index) in case of 0 bribes, 2 updates in case of 1 bribe and only 1 update in case of 2 bribes.