Quick Overview

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

Company: Commure

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

# 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.

Quick Answer: 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.

Implement filter_people over parallel arrays ages, person_occupations, and salaries. Ages, salaries, and active numeric bounds are canonical signed-64 decimal strings so every supported language compares them exactly. Return matching indices in original order. Bounds are inclusive; the empty string disables that one bound. An empty accepted_occupations array disables occupation filtering, otherwise matching is case-sensitive. Do not mutate inputs.

Constraints

  • All three person arrays have equal length up to 200,000.
  • Every age and salary is a canonical decimal string for a signed 64-bit integer: exactly '0' or an optional minus sign followed by [1-9][0-9]*.
  • Each numeric bound is either the empty disabled sentinel or the same canonical signed-64 form.
  • When both bounds in one dimension are enabled, the lower bound does not exceed the upper bound.
  • Occupation strings are case-sensitive.

Examples

Input: ([], [], [], "", "", [], "", "")

Expected Output: []

Explanation: An empty population has no matches.

Input: (["20","30"], ["artist","engineer"], ["50000","90000"], "", "", [], "", "")

Expected Output: [0, 1]

Explanation: All filters disabled preserves every index.

Hints

  1. Treat each disabled filter independently.
  2. Append indices during one left-to-right pass to preserve order.

Loading coding console...