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
Coding: Infectious Disease Simulation
00:00
5 left

Coding: Infectious Disease Simulation

MediumPython

Problem

Coding question about infectious diseases with multiple parts: 1) Only infection status, how long has it been infected? 2) Adding immunity status. 3) After D days of infection, how long until stability? 4) Including death status.

Implement analyze_disease(events, D, last_day). Each event is [person_id, day, status], where status is S, I, T, M, or X. Return an object keyed by person ID containing infected, infection_duration, immune, days_to_stability, and dead. Infection duration ends at the first T, M, or X event, or at the end of last_day if no ending event exists.

Constraints

  • 1 <= events.length <= 10^5
  • Each event has the form [person_id, day, status]
  • 0 <= person_id <= 10^9
  • 0 <= day <= last_day
  • 1 <= D <= last_day + 1
  • status is one of "S", "I", "T", "M", or "X"
  • Each person has at most one initial infection event

Function Signature

def analyze_disease(events, D, last_day):
Interviewer

Your question is Coding: Infectious Disease Simulation. 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.