Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Offline Sync with Conflict Resolution

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

Your question is Offline Sync with Conflict Resolution. 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

Design a function that merges offline mobile actions into server state. Each action has an item_id, operation type, timestamp, and op_id; duplicate retries must be ignored, the merge order must be deterministic, and conflicting items must be returned separately.

Inputs and Output

  • local_ops: list of (item_id, op_type, timestamp, op_id)
  • server_state: current item state before sync
  • remote_changes: list of (item_id, op_type, timestamp)
  • Return (final_state, conflicts)

Merge Rules

  • Ignore repeated op_id values
  • Apply local actions in timestamp order with deterministic tie-breaking
  • Flag an item as a conflict if remote changed it after the sync point
  • Do not apply conflicting local actions
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output