+ 2

Need help to optimize code

Hello folks need your valuable suggestions to improve this code performance: https://code.sololearn.com/c54y0qiExYLM/?ref=app

8th Aug 2018, 3:59 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Answers
+ 1
Robin thanks for your help.. I started with same concept but could not come to conclusion for bribe count... as all positive and negative values will be equal to 0.... I got idea from explanation that 3 elevation of 2 position changes makes count as 6... how you came to know one bribe for six as seventh bribe? 4-3 and 7-6 both seems similar to me... then count should be 8 bribe...
9th Aug 2018, 3:46 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
wow... great Robin ... O(N^2) of this is far more better than my original code.... Just wondering whether bribe count will get affected or updated unnecessarily as you are not updating queue based on loop j just before next iteration of i.... need to check more test cases and will do this at my end... but seems what you have suggested is the better code...
9th Aug 2018, 6:22 AM
Ketan Lalcheta
Ketan Lalcheta - avatar