Skip to main content

Number Of Employees Who Met the Target

Problem Description​

There are n employees in a company, numbered from 0 to n - 1. Each employee i has worked for hours[i] hours in the company. The company requires each employee to work for at least target hours. You are given a 0-indexed array of non-negative integers hours of length n and a non-negative integer target. Return the integer denoting the number of employees who worked at least target hours.

Examples​

Example 1:

Input: hours = [0,1,2,3,4], target = 2
Output: 3
Explanation: The company wants each employee to work for at least 2 hours.
- Employee 0 worked for 0 hours and didn't meet the target.
- Employee 1 worked for 1 hours and didn't meet the target.
- Employee 2 worked for 2 hours and met the target.
- Employee 3 worked for 3 hours and met the target.
- Employee 4 worked for 4 hours and met the target.
There are 3 employees who met the target.

Example 2:

Input: hours = [5,1,4,2,2], target = 6
Output: 0
Explanation: The company wants each employee to work for at least 6 hours.
There are 0 employees who met the target.

Complexity Analysis​

*** Time Complexity:** O(n)O(n)

*** Space Complexity:** O(n)O(n)

Constraints​

  • 1 <= n == hours.length <= 50
  • 0 <= hours[i], target <= 105

Solution​

Approach​

The goal is to determine the number of employees who have worked a number of hours greater than or equal to a specified target. To achieve this, the solution iterates through an array of integers, where each integer represents the number of hours worked by an employee. A counter variable is initialized to zero. As the loop progresses, each element of the array is checked to see if it meets or exceeds the target hours. If it does, the counter is incremented. After the loop has processed all elements, the counter, which now holds the number of employees who met or exceeded the target hours, is returned as the result. This approach ensures that every employee's hours are checked efficiently in a single pass through the array, making it both straightforward and efficient.

Code in Different Languages​

Written by @ImmidiSivani
class Solution {
public:
int numberOfEmployeesWhoMetTarget(vector<int>& hours, int target) {
int c = 0;
for (int hour : hours) {
if (hour >= target) {
c++;
}
}
return c;
}
};


References​