algoadvance

You are given a list of integers, hours, where each integer represents the number of hours an employee has worked in a week. You are also given an integer target which represents the target number of hours an employee needs to meet or exceed. Your task is to write a function that returns the number of employees who have met or exceeded the target number of hours.

Function Signature:

def number_of_employees_met_target(hours: List[int], target: int) -> int:

Clarifying Questions

  1. Q: Can the hours list contain negative numbers?
    • A: No, the hours worked by an employee cannot be negative.
  2. Q: What is the size limit for the hours list?
    • A: The size of the list can go up to (10^5).
  3. Q: Can target be zero?
    • A: Yes, target can be zero, indicating that any number of hours worked would meet the target.
  4. Q: Will the input always be valid, i.e., no null or edge cases like very large numbers?
    • A: You can assume the input is valid within the reasonable constraint parameters specified.

Strategy

  1. Iterate through the hours list.
  2. Count the number of elements in hours that are greater than or equal to target.

This approach is straightforward and leverages simple iteration and comparison, ensuring an efficient solution.

Time Complexity

Code

from typing import List

def number_of_employees_met_target(hours: List[int], target: int) -> int:
    count = 0
    for hour in hours:
        if hour >= target:
            count += 1
    return count

# Example usage
hours = [40, 35, 50, 45, 30]
target = 40
print(number_of_employees_met_target(hours, target))  # Output should be 3

This function number_of_employees_met_target will iterate through the hours list, count every hour value that meets or exceeds the target, and return this count. Here, we assume the hours list and target are given as input parameters.

Example Execution

For hours = [40, 35, 50, 45, 30] and target = 40:

The function returns 3, indicating 3 employees have met or exceeded the target of 40 hours.

Try our interview co-pilot at AlgoAdvance.com