Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

RC Error-Rate Loop Logic

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

Your question is RC Error-Rate Loop Logic. 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

Explain how you would implement the missing checkRC logic for the following pattern: you repeatedly call doSomething() returning rc (0 good, 1 error), and you exit if errors exceed MAX_ERROR within TIME seconds.

Implement check_rc(events, max_error, time_seconds). events contains [timestamp, rc] pairs sorted by nondecreasing timestamp. Return the zero-based index of the first event that causes more than max_error errors in the inclusive interval [timestamp - time_seconds, timestamp]; return -1 if the threshold is never exceeded. Assume each rc is either 0 or 1.

Constraints

  • 0 <= events.length <= 5000
  • events[i] = [timestamp, rc]
  • 0 <= timestamp <= 10^9
  • Timestamps are sorted in nondecreasing order
  • rc is either 0 or 1
  • 0 <= max_error <= events.length
  • 0 <= time_seconds <= 10^9

Function Signature

def check_rc(events, max_error, time_seconds):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output