All practice tasks

Coding (Algo)

Latest Notification Payload

Hash map · Easy

A notification consumer receives corrected payloads under the same ID. Display order should follow first arrival while contents use the last update.

Deduplicate by ID using the last payload and the first occurrence order.

Input

Call

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

Input object

{ events:{id:string,value:integer}[] }

What each field means

  • events — notification records in arrival order. Each contains an id and integer value.

Output

Return value and rules

  • Return one {id, value} object per distinct ID.
  • Use the last value received for that ID.
  • Order IDs by their first appearance, not their last update.

Constraints

  • 0 <= events.length <= 100000
  • IDs are case-sensitive ASCII strings up to 40 characters; values in [-1000000,1000000].

Examples

Example 1

{
  "events": [
    {
      "id": "a",
      "value": 1
    },
    {
      "id": "b",
      "value": 2
    },
    {
      "id": "a",
      "value": 3
    }
  ]
}

Returns

[
  {
    "id": "a",
    "value": 3
  },
  {
    "id": "b",
    "value": 2
  }
]

Example 2

{
  "events": []
}

Returns

[]

Required complexity

O(n) time and O(u) space

What this task practices

Latest Notification Payload 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 easy 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.