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 fromsolve.
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 fromorder.
Output
Return value and rules
- Return the first ID in
orderthat also occurs inerrors. - Use layout order, not the order of errors.
- Return
nullif 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
nullRequired complexity
O(n + m) time and O(m) space