Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Iterator Implementation and Usage
00:00
5 left

Iterator Implementation and Usage

EasyPython

Problem

Foursquare Explore may return a sequence of ranked venue results that a caller consumes one at a time. Implement an iterator supporting next() and hasNext() without modifying the underlying results.

Your solution must provide a run_iterator(values, operations) function. It receives a list of result identifiers and a list of operations, then executes them in order. The operation "hasNext" returns whether another result is available. The operation "next" returns the next result and advances the iterator. If next() is called after exhaustion, return None.

The iterator should maintain only its current position and must not remove elements from the input list. Return a list containing the result of every operation, preserving operation order.

Formal Specification

  • Input values: a list of integers representing Explore result identifiers.
  • Input operations: a list containing only the strings "next" and "hasNext".
  • Output: a list of booleans, integers, or None, with one entry per operation.

Constraints

  • 0 <= len(values) <= 10^5
  • 1 <= len(operations) <= 2 * 10^5
  • Every operation is either "next" or "hasNext".
  • Values may be negative or repeated.

Function Signature

def run_iterator(values, operations):
Interviewer

Your question is Iterator Implementation and Usage. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.