All practice tasks

Coding (Algo)

First Invalid Field

Input validation · Easy

A form must move focus to the earliest invalid field in the visual layout rather than the order in which validation responses arrived.

Return the first field ID in layout order that appears in the error set.

Input

Call

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

Input object

{ order: string[], errors: string[] }. order has unique IDs; errors may repeat IDs or contain IDs not in the layout

What each field means

  • order — unique field IDs in their visible top-to-bottom order.
  • errors — IDs with validation errors; it may include duplicates or fields absent from order.

Output

Return value and rules

  • Return the first ID in order that also occurs in errors.
  • Use layout order, not the order of errors.
  • Return null if no visible field has an error.

Constraints

  • 0 <= order.length, errors.length <= 100000
  • IDs are nonempty case-sensitive ASCII strings of at most 40 characters.

Examples

Example 1

{
  "errors": [
    "email",
    "name"
  ],
  "order": [
    "name",
    "email"
  ]
}

Returns

"name"

Example 2

{
  "errors": [
    "x"
  ],
  "order": []
}

Returns

null

Required complexity

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

What this task practices

First Invalid Field 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.