I am trying to solve a problem that was posed during an interview. I could not solve it during the interview, so I ask you to help him to know this.
The problem is this:
Write a class with a method that takes an integer and returns the integer, which is the largest value that the method has called in the last ten minutes.
From what I understand, I have to store all the values โโthat have been called by the method in the last 10 minutes. Values โโmust be stored in an efficient data structure, as this method can be called several times per second.
Do you have any suggestions as to which data structure should be more efficient for this? Also, since it is a window drag time, how can I clear values โโthat have expired?
And what should be the best way to get the maximum value depending on the data structure used?
I have the base code:
private final static ScheduledExecutorService EXECUTOR_SERVICE = Executors.newSingleThreadScheduledExecutor(); private static List<Integer> values = new ArrayList<Integer>(); public int method(final int value){ values.add(value);
source share