Scenario:
For a list that have 3 elements:
[A, B, C]
You can circular access it as many times as you want.
And there is an additional counting function records access count of each element.
For example, if accessing it 7 times, should return:
[A, B, C, A, B, C, A]
And have access count of each element as following:
+–––––––––––+–––––––––––––––+
| Element | Access count |
+–––––––––––––––––––––––––––+
| A | 3 |
+–––––––––––––––––––––––––––+
| B | 2 |
+–––––––––––––––––––––––––––+
| C | 2 |
+–––––––––––+–––––––––––––––+
Add another additional function that allow caller to specify a elements list that should be filtered. Still use 7 times accessing as a example, filtering [C]
:
[A, B, A, B, A, B, A]
+–––––––––––+–––––––––––––––+
| Element | Access count |
+–––––––––––––––––––––––––––+
| A | 4 |
+–––––––––––––––––––––––––––+
| B | 3 |
+–––––––––––––––––––––––––––+
| C | 0 |
+–––––––––––+–––––––––––––––+
And the subsequent calling on getNextOne()
should always fetch the one that access count is low. Simulate a load-balanced accessing count implementation. So, if second caller attempt to accessing it 10 times, should return:
[C, C, C, B, C, A, B, C, A, B, C, A]
+–––––––––––+–––––––––––––––+
| Element | Access count |
+–––––––––––––––––––––––––––+
| A | 7 |
+–––––––––––––––––––––––––––+
| B | 6 |
+–––––––––––––––––––––––––––+
| C | 6 |
+–––––––––––+–––––––––––––––+