I am working on a coding challenge on a banking application where I need to fetch number of transactions in last 60 seconds.
For that I am using java.sql.Timestamp
as a key of a map
like below:
Map<Timestamp, List<Transaction>> transactions1 = new HashMap<>();
Here value is the list of transactions done at that time.
I can't use DB. I know how to iterate through the map and fetch the data but for that I need to iterate the whole map
which will be time consuming.
1) My question is is
Map
the right data structure for this problem?2) If so then how can I reduce it(may be by
NavigableMap
)?
I am not asking for coding solution but the proper design/ data structure that I should use.