Katkat

Filter People by Optional Criteria

CommureSoftware Engineer · Technical Screen

Last 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: string
  • last_name: string
  • age: integer
  • occupation: string
  • salary: integer

Return a new list containing the records that satisfy every active filter, in their original order.

Filter semantics

  • If min_age is not None, require age >= min_age.
  • If max_age is not None, require age <= max_age.
  • If occupations is not None, it is a nonempty set of accepted occupation strings and the record's occupation must be a member.
  • If min_salary is not None, require salary >= min_salary.
  • If max_salary is not None, require salary <= max_salary.
  • A None bound 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.