Prasanna Raman wrote:That other function is supposed to find all customer IDs that have spent more than the allocated amount in any 12 hour period (the time argument is in chronological order in the list).
Okay, so you need a sliding window?
First, create a strongly typed representation of your input:
Now, given a stream of expenses, you will want to collect them into windows of a preset duration. A window might look like this:
<br /> Collect your expenses:
Finally, for each customer in the map, iterate over the time windows and if the sum of the monetary amounts of the expenses in a single window exceed your maximum, you'll know too much has been spent.