All practice tasks

Coding (Algo)

Stable Feed Pagination

Sorting · Medium

A client merges API feed records before slicing a page. Retries may repeat IDs with newer timestamps.

Deduplicate by ID, keep the latest timestamp, sort newest first then smaller numeric ID, and paginate the full set.

Input

Call

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

Input object

{ records:{id:integer,time:integer}[], offset:integer, limit:integer }

What each field means

  • records — feed records with numeric id and time; the same ID may occur more than once.
  • offset — number of unique sorted records to skip.
  • limit — maximum number of IDs to include in the page.

Output

Return value and rules

  • Keep the greatest timestamp for each ID, then sort by timestamp descending and ID ascending.
  • Return {total, ids}: total is the full unique-record count; ids is the requested page.
  • An exhausted page or zero limit returns empty ids without changing total.

Constraints

  • 0 <= records.length <= 100000; offset in [0,1000000000]; limit in [0,100000]
  • IDs and times in [0,1000000000]. Repeated identical records are harmless.

Examples

Example 1

{
  "limit": 1,
  "offset": 0,
  "records": [
    {
      "id": 2,
      "time": 1
    },
    {
      "id": 1,
      "time": 3
    },
    {
      "id": 2,
      "time": 4
    }
  ]
}

Returns

{
  "total": 2,
  "ids": [
    2
  ]
}

Example 2

{
  "limit": 1,
  "offset": 0,
  "records": []
}

Returns

{
  "total": 0,
  "ids": []
}

Required complexity

O(n + u log u) time and O(u) space

What this task practices

Stable Feed Pagination 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.