IBM software developer OA -IBM -OA代写 -OA ghost writing -一亩三分地 -OA help

Question

Implement a prototype of a simple cache query handler.

There are n data entries stored in the cache. Each entry is of the form {timestamp, key, value}, where timestamp represents the time at which the entry was stored in the cache, key represents the ID assigned to the cache entry, and value represents the data value of the entry, an integer represented as a 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 cache entry to find, and timestamp represents the time the entry was added.

Given two 2D arrays of strings, cache_entries, and queries, of sizes n x 3 and q x 2 respectively, return an array of size q with the data values for each query.


Example

cache_entries = [["12:30:22", "a2er5i80", "125"], 
                 ["09:07:47", "io09ju56", "341"], 
                 ["01:23:09", "a2er5i80", "764"]]

queries = [["a2er5i80", "01:23:09"], 
           ["io09ju56", "09:07:47"]]
  • 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".
Event TypeDataCacheQuery Result
Update cache["09:07:47", "io09ju56", "341"]io09ju56 = 341-
Query["io09ju56", "09:07:47"]io09ju56 = 341341
Update cache["12:30:22", "a2er5i80", "125"]io09ju56 = 341, a2er5i80 = 125-
Update Cache["01:23:09", "a2er5i80", "764"]io09ju56 = 341, a2er5i80 = 764-
Query["a2er5i80", "01:23:09"]io09ju56 = 341, a2er5i80 = 764764

Return [764, 341].


Function Description

Complete the function getQueryAnswers in the editor below.

getQueryAnswers has the following parameters:

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

Returns
int [q]: the answers to the queries


Constraints

  • 1 <= n <= 100000
  • 1 <= q <= 100000
  • 1 <= int(cache_entries[i][2]) <= 100000000
  • 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 of only lowercase English letters (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.

CSOAhelp长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

CSOAhelp consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *