The Map Reducer
A medium Python mock interview question on DataDriven. Practice with AI-powered feedback, real code execution, and a hire/no-hire decision.
- Domain
- Python
- Difficulty
- medium
- Seniority
- L3
Interview Prompt
Given a list of `values`, a `mapper`, and a `reducer`, return the single value produced by applying `mapper` to every element and then reducing the mapped results left-to-right with `reducer`. The catch: `mapper` and `reducer` arrive as SOURCE STRINGS of lambda expressions (for example the string "lambda x: x * 2" and the string "lambda a, b: a + b"), so you must `eval` each string into a real callable before you can call it. `mapper` takes one argument and returns a transformed value; `reducer` takes two arguments (accumulator, next) and returns one combined value, applied cumulatively from left to right like `functools.reduce`. Return the final reduced value. If `values` is empty, return `None`.
Summary
Map it. Reduce it. One answer.
How This Interview Works
- Read the vague prompt (just like a real interview)
- Ask clarifying questions to the AI interviewer
- Write your python solution with real code execution
- Get instant feedback and a hire/no-hire decision