Kotlinlearncs.online LogoJava
Return to List

Solve: Cache Handler

Created By: Pranav Narayanan
/ Version: 2024.9.0

Write a method cacheHandler that takes a 2D String array of cache entries, and returns a Map<String, Int> containing every cache key and its most recent value.

The String array has 3 columns: the cache id, the timestamp of that entry(hh:mm:ss), and the Int value at that time, in that order. Your Map should contain only the most recent entry for any given key based on the timestamps. In the case where you re-encounter the same timestamp for the same key, do NOT change the value.

You may assume that the input follows this format, although it may be empty. You will need the String.toInt() method to convert a String to an Int value.

Hint: How can you keep track of the most recent time for every key?

Related Lessons

Stuck? You may find these lessons helpful:

Report a Problem

Attribution must link to this page: https://www.learncs.online/solve/kotlin/cache-handler/[email protected]