We use cookies (including Google cookies) to personalize ads and analyze traffic. By continuing to use our site, you accept our Privacy Policy.

Number of Employees Who Met the Target

Difficulty: Easy


Problem Description

Given a list of hours worked by employees and a target number of hours, determine how many employees have worked at least the target number of hours.


Key Insights

  • The problem involves iterating through an array of integers representing hours worked.
  • A simple comparison of each employee's hours against the target is needed.
  • The constraints are manageable, allowing for a straightforward solution without optimization for large input sizes.

Space and Time Complexity

Time Complexity: O(n) - where n is the number of employees, as we need to check each employee's hours. Space Complexity: O(1) - as we use a constant amount of space to count the employees who meet the target.


Solution

To solve the problem, we will use a single loop to iterate through the list of hours. For each employee's hours, we will check if it meets or exceeds the target. We maintain a counter to keep track of how many employees meet the requirement. This approach uses an array data structure to hold the hours and simple conditional statements to perform the comparisons.


Code Solutions

def numEmployeesWhoMetTarget(hours, target):
    count = 0
    for hour in hours:
        if hour >= target:
            count += 1
    return count
← Back to All Questions