Filtering · Easy
A control plane receives one health snapshot per instance. Traffic may go only to ready instances below a fixed error threshold.
Return eligible IDs in ascending ASCII order.
Input
Call
- Implement
solve(input)and return its result. Do not print fromsolve.
Input object
{ instances:{id:string,ready:boolean,errors:integer}[], maximumErrors:integer }
Input rules
- IDs are unique.
What each field means
instances— unique IDs with readiness flags and error counts.maximumErrors— largest permitted error count, inclusive.
Output
Return value and rules
- Return IDs with
ready: trueanderrors <= maximumErrors. - Sort IDs in ASCII order. A low error count does not compensate for not being ready.
- No eligible instances produce
[].
Constraints
- 0 <= instances.length <= 100000; errors and maximumErrors in [0,1000000]
- IDs are nonempty lowercase ASCII strings of at most 40 characters.
Examples
Example 1
{
"instances": [
{
"id": "b",
"ready": true,
"errors": 2
},
{
"id": "a",
"ready": true,
"errors": 1
},
{
"id": "c",
"ready": false,
"errors": 0
}
],
"maximumErrors": 1
}Returns
[
"a"
]Example 2
{
"instances": [],
"maximumErrors": 0
}Returns
[]Required complexity
O(n log n) time and O(n) space