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
|
28 Discussions
|
Please Login in order to post a comment
How can the expected output from this q be 7?
q = [1, 2, 5, 3, 7, 8, 6, 4]
Iterate from right to left, if you have seen 3 values lower than the current it's too chaotic, othewise add the seen list index to the bribe count.
bisect used to maintain order, only need to keep the 3 smallest values seen.
Python3: another O(N) (??? maybe ???)
Python - the key for me was to think about 'how many people to the right have numbers smaller than me' as those people must have been overtaken (bribed). Then it became a matter of doing the check in a fast enough way to handle the test cases...
C#