#14Count the dedup savingsEasyAgentic AI
Count the dedup savings
Background
With shared memory, a query is only actually searched the first time it's seen; later repeats are cache hits. Replaying the sequence of queries the executors issued tells you how much retrieval was saved.
Problem statement
Implement dedup_savings(queries) returning (searches_performed, cache_hits).
Input
queries— the ordered list of search queries the executors issued.
Output
Returns a tuple (searches_performed, cache_hits):
searches_performed— number of distinct queries (first occurrences),cache_hits— number of repeats served from cache (len(queries) - searches_performed).
Examples
Example 1
Input: ["AlphaCode", "AlphaCode", "Codex", "AlphaCode"]
Output: (2, 2)
Explanation: searched AlphaCode and Codex once each (2); the two repeat AlphaCode lookups are cache hits (2).
Example 2 — all unique
Input: ["a", "b", "c"]
Output: (3, 0)
Constraints
- A query is searched only on its first occurrence; later ones are hits.
searches_performed + cache_hits == len(queries).
Notes
- This is the post-mortem number: shared memory turns N issued queries into
searches_performedreal retrievals.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Reference example: repeated query is a cache hit
- •Sample: all unique -> no hits
- •Example: all the same -> one search