DataDriven
LearnPracticeInterviewDiscussDailyJobs

The Frequency Eviction

A hard Python mock interview question on DataDriven. Practice with AI-powered feedback, real code execution, and a hire/no-hire decision.

Domain
Python
Difficulty
hard
Seniority
L5

Interview Prompt

You are replaying a captured operation log against an LFU (least-frequently-used) cache to reproduce the value each call returned. The cache holds at most `capacity` entries: `get(key)` returns the stored value or -1 when the key is absent, and `put(key, value)` inserts or updates an entry, where both a successful `get` and an update count as an access toward a key's frequency. When a `put` on a new key would exceed `capacity`, evict the least-frequently-used key first, breaking ties by removing the least-recently-used among them; a cache constructed with `capacity <= 0` stores nothing. `run_lfu_cache(operations, args)` receives parallel lists where `operations[0]` is always "LFUCache" (the constructor) and each `args[i]` is the argument list for `operations[i]`; replay them against one instance and return the result of each call, using `None` for the constructor and for every `put`, and the returned value (or -1) for every `get`.

Summary

When storage is tight, something has to go.

How This Interview Works

  1. Read the vague prompt (just like a real interview)
  2. Ask clarifying questions to the AI interviewer
  3. Write your python solution with real code execution
  4. Get instant feedback and a hire/no-hire decision

Related

  • All Mock Interviews
  • Practice Mode (untimed)
  • Python Interview Questions
  • Data Engineering Interview Prep Guide
  • Practice Problems
  • Daily Challenge