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
|
1187 Discussions
|
Please Login in order to post a comment
My Kotlin version, which sorts the first d elements once, and then adopts binary search to remove/insert old/new elements as the window slides;
public static int activityNotifications(List expenditure, int d) { int notifications = 0; int[] count = new int[expenditure.stream().max(Integer::compareTo).get() + 1];
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: