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

Number: 2876

Difficulty: Easy

Paid? No

Companies: Amazon, Adobe


Problem Description

Given an array representing the number of hours each employee has worked and a target number of hours required, count how many employees have met or exceeded the target hours.


Key Insights

  • You are given a list of non-negative integers representing work hours.
  • A simple iteration through the array is sufficient since the constraints are small.
  • Increment a counter each time an employee's hours are greater than or equal to the target.
  • The solution is straightforward with a single loop.

Space and Time Complexity

Time Complexity: O(n), where n is the number of employees. Space Complexity: O(1), only a counter is used.


Solution

The approach is to iterate over the list of work hours and count the number of employees whose hours are at least the target. Use a simple counter variable initialized to 0, and for every value in the array, increment the counter if the value is greater than or equal to the target. This yields a time-efficient and space-efficient solution. The key data structure is the array provided, and the algorithmic approach is a single linear scan.


Code Solutions

# Define a function to count employees meeting the target
def countEmployees(hours, target):
    count = 0  # Initialize counter to track qualifying employees
    for h in hours:  # Iterate over each employee's work hours
        if h >= target:  # Check if employee's hours are at least the target
            count += 1  # Increment the counter if condition is met
    return count  # Return the final count of employees who met the target

# Example usage:
# hours = [0, 1, 2, 3, 4]
# target = 2
# print(countEmployees(hours, target))  # Output: 3
← Back to All Questions