Problem · Hash Table

Get Query Answers

Learn this problem
EasyIBM logoIBMFULLTIMEOA
See IBM hiring insights

Problem statement

Implement a prototype of a simple cache query handler.

There are n entries stored in the cache. Each entry is of the form {timestamp, key, value}, where time stamp represents the time at which the entry was stored in the cache entry, and value represents the data value of the entry, an integer represented as string. The keys assigned to the cache entries may not be unique. The cache query handler receives q query requests, where each query is of the form {key, timestamp}, where key represents the ID of the query entry to find, and timestamp represents the time the enry was added.

Given 2 2d arr of strings, cache_entries, and queries, of sizes n X 3 and q X 2 respectively, return an arr of size q with the data values for each query.

Function

getQueryAnswers(cache_entries: String[][], queries: String[][]) → int[]

Complete the function getQueryAnswers in the editor.

getQueryAnswers has the following parameters:

  1. string cache_entries[n][3]: the cache data entries
  2. string queries[q][2]: the queries

Returns

int[q]: the answers to the queries

Examples

Example 1

cache_entries = [["01:34:05", "l66klkph", "352"], ["56:38:37", "8pvj20oo", "107"], ["36:17:33", "r0v06eec", "180"], ["20:34:20", "e15y6dv4", "490"]]queries = [["e15y6dv4", "20:34:20"], ["8pvj20oo", "56:38:37"]]return = [490, 107]
:)

Example 2

cache_entries = [["12:30:22","a2er5i80","125"],["09:07:47","ioO9ju56","341"],["01:23:09","a2er5i8O","764"]]queries = [["a2er5i8O", "01:23:09"], ["ioO9ju56", "09:07:47"]]return = [764, 341]
Example 2 illustration
queries[0] corresponds to the data entry at index 2, with value = "764" queries[1] corresponds to the data entry at index 1, with value = "341" Return [764, 341] :)

Constraints

  • 1 ≤ n ≤ 10^5
  • 1 ≤ q ≤ 10^5
  • 1 ≤ int(cache_entries[i][2]) ≤ 10^8
  • cache_entries[i][0] represents a valid timestamp in the format hh:mm:ss
  • size(cache_entries[i][0]) = 8
  • cache_entries[i][1] is an alphanumeric value consisting only of English letters (a-z, A-Z) and digits (0-9)
  • It is guaranteed that the queried {key, timestamp} pair is present in the cache.
  • At a particular timestamp, there can be no duplicate keys.
  • More IBM problems

    drafts saved locally
    public int[] getQueryAnswers(String[][] cacheEntries, String[][] queries) {
      // write your code here
    }
    
    cache_entries[["01:34:05", "l66klkph", "352"], ["56:38:37", "8pvj20oo", "107"], ["36:17:33", "r0v06eec", "180"], ["20:34:20", "e15y6dv4", "490"]]
    queries[["e15y6dv4", "20:34:20"], ["8pvj20oo", "56:38:37"]]
    expected[490, 107]
    checking account