Filter People by Optional Criteria
CommureSoftware Engineer · Technical ScreenLast updated
Implement stable filtering for person records across optional inclusive age and salary bounds plus an optional occupation set. Every enabled criterion must match, disabled bounds use None, and neither the input list nor its records may be mutated.
Filter People by Optional Criteria
Implement filter_people(people, min_age, max_age, occupations, min_salary, max_salary).
Each item in people is a dictionary with these keys:
first_name: stringlast_name: stringage: integeroccupation: stringsalary: integer
Return a new list containing the records that satisfy every active filter, in their original order.
Filter semantics
- If
min_ageis notNone, requireage >= min_age. - If
max_ageis notNone, requireage <= max_age. - If
occupationsis notNone, it is a nonempty set of accepted occupation strings and the record's occupation must be a member. - If
min_salaryis notNone, requiresalary >= min_salary. - If
max_salaryis notNone, requiresalary <= max_salary. - A
Nonebound disables only that bound. - Do not mutate the input list or any record.
Constraints
0 <= len(people) <= 200,000- Ages and salaries fit in signed 64-bit integers.
- Bounds, when both present, are ordered correctly.
- Names and occupation strings are case-sensitive.
Example
For people aged 27, 35, and 42, filtering for ages 30 through 45, occupations in {engineer, designer}, and a minimum salary of 100000 returns only records satisfying all three dimensions.
Candidate clarifications
Confirm inclusivity of ranges, whether string matching is case-sensitive, how disabled filters are represented, and whether result order must be stable.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.