Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Validate Deadline Eligibility Updates

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

Your question is Validate Deadline Eligibility Updates. 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

Scale.ai task workflows may allow an annotator task to receive a later deadline, but only while the task remains eligible for modification. Implement update_deadline to validate all rules and return the updated task when the change is allowed.

A task is eligible only when:

  1. Its status is exactly "pending".
  2. The current time is strictly before its existing deadline.
  3. The current time is no more than modification_window seconds after created_at.
  4. The proposed new_deadline is strictly later than both the current time and the existing deadline.
  5. The proposed deadline does not exceed created_at + max_lifetime.

If every rule passes, return a copy of the task with its deadline replaced by new_deadline. Otherwise, return None. Do not modify the input dictionary when the update is rejected.

Formal Specification

Input is a dictionary containing integer Unix timestamps for created_at, deadline, modification_window, and max_lifetime, plus a string status. The function also receives integer new_deadline and now values. Return a dictionary on success or None on failure.

Constraints

  • Timestamps are integers from 0 through 10^9.
  • 0 <= created_at < deadline <= created_at + max_lifetime.
  • 1 <= modification_window, max_lifetime <= 10^9.
  • status is a non-empty string.
  • The input task dictionary contains all required keys.

Function Signature

def update_deadline(task, new_deadline, now):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output