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.
Fraudulent Activity Notifications
Fraudulent Activity Notifications
Sort by
recency
|
1185 Discussions
|
Please Login in order to post a comment
Similar to @coswaldors53 solution, the idea revolves around being limited to 200. If we maintain an array of the count of previous expenditures, to find the median we need to check at most 200 values for each expenditure, giving .
We need to find the two indices where the median will lie - this will be , where we shift one to the right if is even. Then, we can sweep across the array to see when the number of values visited reaches this point. If we reach this point, then we know that we have found the index where the median lies.
Python solution:
JS:
Here is a Java solution with sorted arrayList and sliding window: