Code Room
CodingHardcod-g972
Subject Storage systemsLevel Senior~32 minCommon in Storage & CDN · Algorithms & data structures interviewsIndustries Technology, Software development

Question

Implement a Count-Min Sketch for approximate frequency counting. It has `depth` rows and `width` columns of integer counters, all starting at 0. For row r (0-indexed) and item key (a string), the column is c(r, key) = (sum((ord(ch) * (r + 7)) for ch in key) * 2654435761 + r * 0x9E3779B1) % width. To add a key with count n, increment counters[r][c(r,key)] by n for every row r. The estimated frequency of a key is the MINIMUM over all rows of counters[r][c(r,key)] (the min reduces overestimation from collisions). Process operations ["add", key, n] and ["estimate", key]; return the list of estimate results in order. depth and width are positive integers.

Implement
count_min_sketch(depth: int, width: int, ops: list[list]) → list[int]
Examples
in[3,1000,[["add","apple",2],["add","apple",3],["estimate","apple"],["estimate","banana"]]]out[5,0]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.