docker build -t metunic-priority-caching-java .
docker run --rm -i metunic-priority-caching-java < input000.txt
- The first line contains an integer, n, the number of log entries.
- The next line contains an integer, 2, the number of parameters to describe a log entry.
- Each line i of the n subsequent lines (where 0 ≤ i < n) contains the log entry in the form described above.
The system receives a sequence of log entries denoting calls made to memory items. Each log entry consists of a timestamp and an item ID.
Example callLogs
input:
[
[1, 1],
[2, 1],
[3, 1],
[4, 2],
[5, 2],
[6, 2]
]
-
First Access to Item 1 (
[1, 1]
):- Priority (
priority
): Starts at0
(new item) - Access Count (
accessCount
): Starts at0
- Priority Update:
- Since it's the first access, priority increases by
2
(now2
)
- Since it's the first access, priority increases by
- Item is not cached (priority less than or equal to
5
)
- Priority (
-
Second Access to Item 1 (
[2, 1]
):- Priority Update:
- Time difference (
timestamp - lastAccessTime
) is2 - 1 = 1
- Priority decreases by
1
(now1
) - Access Count increments to
1
- Priority increases by
2
(now3
)
- Time difference (
- Item is not cached (priority less than or equal to
5
)
- Priority Update:
-
Third Access to Item 1 (
[3, 1]
):- Priority Update:
- Time difference is
3 - 2 = 1
- Priority decreases by
1
(now2
) - Access Count increments to
2
- Priority increases by
2
(now4
)
- Time difference is
- Item is not cached (priority less than or equal to
5
)
- Priority Update:
-
First Access to Item 2 (
[4, 2]
):- Priority (
priority
): Starts at0
(new item) - Access Count (
accessCount
): Starts at0
- Priority Update:
- Since it's the first access, priority increases by
2
(now2
)
- Since it's the first access, priority increases by
- Item is not cached (priority less than or equal to
5
)
- Priority (
-
Second Access to Item 2 (
[5, 2]
):- Priority Update:
- Time difference (
timestamp - lastAccessTime
) is5 - 4 = 1
- Priority decreases by
1
(now1
) - Access Count increments to
1
- Priority increases by
2
(now3
)
- Time difference (
- Item is not cached (priority less than or equal to
5
)
- Priority Update:
-
Third Access to Item 2 (
[6, 2]
):- Priority Update:
- Time difference is
6 - 5 = 1
- Priority decreases by
1
(now2
) - Access Count increments to
2
- Priority increases by
2
(now4
)
- Time difference is
- Item is cached (priority exceeds
5
)
- Priority Update:
The function should return the IDs of items that are currently cached in ascending order.
For the given callLogs
, the expected cached items are [1, 2]
.