All practice tasks

Coding (Algo)

First Replayed Request

Hash set · Easy

An API audit stream contains request IDs in arrival order. Operations wants the first event that repeats an earlier ID.

Return the index of the earliest duplicate occurrence.

Input

Call

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

Input object

{ ids:string[] }

Input rules

  • IDs are case-sensitive and may be empty.

What each field means

  • ids — request IDs in arrival order. IDs are case-sensitive, and empty IDs are valid.

Output

Return value and rules

  • Return the zero-based index of the first arrival whose ID appeared earlier.
  • Return the duplicate occurrence’s index, not the original occurrence’s index.
  • Return -1 if every arrival has a new ID.

Constraints

  • 0 <= ids.length <= 100000
  • Each ID contains at most 80 ASCII characters.

Examples

Example 1

{
  "ids": [
    "a",
    "b",
    "b",
    "a"
  ]
}

Returns

2

Example 2

{
  "ids": []
}

Returns

-1

Required complexity

O(n) time and O(n) space

What this task practices

First Replayed Request 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.