FastPrepCache Query Handler
Problems/Cache Query Handler

Cache Query Handler

IBM logoIBM● EasyNEW GRADOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

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 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.

Function

cacheQueryHandler(cacheEntries: String[][], queries: String[][]) → String[]

Examples

Example 1

cacheEntries = [["12:30:22", "a2er5i80", "125"], ["09:07:47", "i09ju56", "341"], ["01:23:09", "a2er5i80", "764"]]queries = [["a2er5i80", "01:23:09"], ["i09ju56", "09:07:47"]]return = ["764", "341"]
Example 1 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"

Example 2

cacheEntries = [["12:30:22", "a2er5i80", "125"], ["09:07:47", "i09ju56", "341"], ["01:23:09", "a2er5i80", "764"]]queries = [["a2er5i80", "01:23:09"], ["i09ju56", "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"

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 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.

More IBM interview questions

  • Missing IntervalsOA · Seen Nov 2026
  • Count Peaks and ValleysOA · Seen Nov 2026
  • Last Object Exit TimeOA · Seen Nov 2026
  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
  • Alternate Odd and Even Numbers with Two GoroutinesPHONE SCREEN · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Nov 2026
  • Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
  • Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Branch with the Most FilesCapital One · OACapital One interview questions
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • First Non-Repeating CharacterAmazon · OA · ONSITE INTERVIEW
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • Count Palindrome Addition ChoicesThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
  • Count Palindrome Addition ChoicesHudson River Trading · OAHudson River Trading interview questions
  • Count Phrases Formed by Anagram ReplacementWells Fargo · OAWells Fargo interview questions
  • Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
  • Minimum Operations to Reduce a Transaction LedgerVisa · OAVisa interview questions

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public String[] cacheQueryHandler(String[][] cacheEntries, String[][] queries) {
      // write your code here
    }

}
Checking account…