DataDriven
LearnPracticeInterviewDiscussDailyJobs

The Custom Iterator

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
L4

Interview Prompt

Implement a Range class accepting (start, stop, step=1) that supports __iter__ and __next__, reimplementing the built-in range() as a custom iterator. The test harness drives your class through a `run_operations(operations, arguments)` driver. `operations` is a list of operation names and `arguments` is a parallel list of positional-argument lists. For each index i: - "Range": construct a new Range with `Range(*arguments[i])` (stash it as the current instance) and append None to the results. - "iterate": collect `list(iter(current_range))` from the most recently constructed Range and append that list to the results. Return the list of per-operation results, in order. __next__ must raise StopIteration when iteration is exhausted: for a positive step, when current >= stop; for a negative step, when current <= stop. So Range(0, 5, 1) yields [0, 1, 2, 3, 4] and Range(10, 0, -2) yields [10, 8, 6, 4, 2].

Summary

Some sequences follow their own rules.

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