Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Virus Memory Consumption Timing

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Virus Memory Consumption Timing. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output