Dataford
Interview QuestionsInterview GuidesExperiencesCoachingPricing
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
Debug HashMap Iteration
00:00
5 left

Debug HashMap Iteration

MediumSQL · PostgreSQL

Problem

Find the error in a HashMap iteration loop using keySet().

Represent each iteration and its events relationally. Treat an iteration as erroneous when a structural map mutation occurs while the keys are being traversed.

Output

  1. Return one row per erroneous iteration with map_name, run_id, mutation_count, and error
  2. Include only iterations with at least one PUT, REMOVE, or CLEAR event
  3. Order by map_name, then run_id

Schema

hash_maps
ColumnTypeDescription
map_idPKINTUnique identifier for the map
map_nameVARCHAR(100)Name of the map being traversed
iteration_runs
ColumnTypeDescription
run_idPKINTUnique identifier for an iteration
map_idINTMap traversed by the iteration
started_atTIMESTAMPIteration start timestamp
completed_atTIMESTAMPIteration completion timestamp
iteration_events
ColumnTypeDescription
event_idPKINTUnique event identifier
run_idINTIteration associated with the event
event_typeVARCHAR(20)Operation observed during iteration
key_textVARCHAR(100)Map key involved in the event
Tableshash_mapsiteration_runsiteration_events
Interviewer

Your question is Debug HashMap Iteration. Start with the requirements and the three tables 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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.