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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Virus Memory Consumption Timing
00:00
5 left

Virus Memory Consumption Timing

MediumPython

Problem

A monitoring simulation for KeyValue infrastructure models a virus that consumes t bits during the first second, t + 1 bits during the second, and one additional bit more each subsequent second. Given the available RAM and the initial consumption t, return the maximum number of complete seconds the virus can run.

The virus may consume memory only when the full amount required for that second is available. Do not simulate one second at a time, and do not use floating-point arithmetic.

Formal Specification

Implement max_survival_time(memory, t).

  • memory is a non-negative integer representing available RAM bits.
  • t is a positive integer representing first-second consumption.
  • Return an integer k, where k is the largest value satisfying: t + (t + 1) + ... + (t + k - 1) <= memory.

Constraints

  • 0 <= memory <= 10^18
  • 1 <= t <= 10^9
  • The answer must not be computed by simulating every second
  • Floating-point arithmetic is not reliable for boundary decisions

Function Signature

def max_survival_time(memory, t):
Interviewer

Your question is Virus Memory Consumption Timing. 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.