Hone logo
Hone
Problems

Employees With Missing Information

Many organizations store employee data in databases or spreadsheets. Sometimes, this data is incomplete, with certain fields missing for some employees. This challenge asks you to identify employees with missing information based on a defined set of required fields, helping ensure data integrity and enabling targeted data collection efforts.

Problem Description

You are given a dataset representing employee information. Each employee is represented as a record (e.g., a dictionary, object, or row in a table) containing various attributes. Your task is to identify and return a list of employee records where any of the required fields are missing (i.e., have a null or empty value).

What needs to be achieved:

Write an algorithm that takes a list of employee records and a list of required fields as input. The algorithm should iterate through the employee records and check if all required fields are present and have non-empty values. If any required field is missing for an employee, that employee record should be added to a result list.

Key requirements:

  • The algorithm must handle different data types for the fields (strings, numbers, booleans).
  • Missing values are considered to be null, None, or an empty string ("").
  • The algorithm should be efficient, especially when dealing with a large number of employee records.

Expected behavior:

The algorithm should return a list containing only the employee records that have at least one missing required field. The order of the returned records should be the same as the order in the input list.

Edge cases to consider:

  • Empty input list of employee records.
  • Empty list of required fields (in this case, no employees should be considered missing).
  • Employee records with no fields at all.
  • Required fields that do not exist in some employee records.
  • Fields with values that are technically present but should be considered missing (e.g., a number field with a value of 0, which might be valid or missing depending on the context – assume 0 is a valid value).

Examples

Example 1:

Input:
employees = [
    {"id": 1, "name": "Alice", "department": "Sales", "salary": 50000},
    {"id": 2, "name": "Bob", "department": None, "salary": 60000},
    {"id": 3, "name": "Charlie", "department": "Marketing", "salary": 70000},
    {"id": 4, "name": "David", "department": "IT", "salary": None}
]
required_fields = ["name", "department", "salary"]
Output:
[
    {"id": 2, "name": "Bob", "department": None, "salary": 60000},
    {"id": 4, "name": "David", "department": "IT", "salary": None}
]
Explanation: Bob's department is None, and David's salary is None, so they are considered to have missing information.

Example 2:

Input:
employees = [
    {"id": 1, "name": "Alice", "department": "Sales"},
    {"id": 2, "name": "Bob", "department": "Marketing"}
]
required_fields = ["salary"]
Output:
[]
Explanation: None of the employees are missing the "salary" field, even though it's not present in their records.

Example 3: (Edge Case)

Input:
employees = []
required_fields = ["name", "department"]
Output:
[]
Explanation: The input list of employees is empty, so the output is an empty list.

Constraints

  • The number of employee records can be up to 10,000.
  • The number of required fields can be up to 10.
  • Each employee record can have up to 20 fields.
  • Field values can be strings, numbers, or booleans.
  • The algorithm should complete within 1 second for the given constraints.

Notes

Consider using a loop to iterate through the employee records and another loop (or a more efficient lookup) to check for the presence and validity of each required field. Think about how to handle different data types when checking for "missing" values. The definition of "missing" is null, None, or "". Focus on clarity and efficiency in your solution.

Loading editor...
plaintext