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.
- New Year Chaos
- Discussions
New Year Chaos
New Year Chaos
Sort by
recency
|
268 Discussions
|
Please Login in order to post a comment
running my code in local IDE for List.of(1, 2, 5, 3, 7, 8, 6, 4) prints "Too chaotic". even using "Test agains custom input", I have same outcome. but when using [Run Code] button, it fails.
any suggestions?
Here is the Simple and Sweet solution
Swift implementation following amoreno_ing:
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.