All practice tasks

Coding (Algo)

Merge Offline Revisions

Two pointers · Medium

A mobile client and server each provide record revisions sorted by ID. The merged snapshot must keep the newest revision for shared IDs.

Merge both lists without re-sorting and resolve equal-version conflicts in favor of the server.

Input

Call

  • Implement solve(input) and return its result. Do not print from solve.

Input object

{ local:{id:integer,version:integer,value:string}[], server:{id:integer,version:integer,value:string}[] }

Input rules

  • Each list has strictly increasing unique IDs.

What each field means

  • local and server — record lists already sorted by increasing ID.
  • Each record has id, version and value; IDs are unique within each list.

Output

Return value and rules

  • Return one merged record per ID, ordered by ID.
  • For an ID on both sides, choose the greater version; equal versions choose the server record.
  • Keep records appearing on only one side. Do not re-sort or mutate the input lists.

Constraints

  • Each list has at most 100000 records
  • IDs and versions are in [0,1000000000]; values are ASCII strings of at most 40 characters. Do not mutate input.

Examples

Example 1

{
  "local": [
    {
      "id": 1,
      "version": 1,
      "value": "a"
    }
  ],
  "server": [
    {
      "id": 1,
      "version": 2,
      "value": "b"
    }
  ]
}

Returns

[
  {
    "id": 1,
    "version": 2,
    "value": "b"
  }
]

Example 2

{
  "local": [],
  "server": []
}

Returns

[]

Required complexity

O(n + m) time and O(n + m) output space

What this task practices

Merge Offline Revisions is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.