Number of Employees Who Met the Target

easy array counting iteration

Problem

There are n employees. Employee i worked hours[i] hours. The company requires every employee to work at least target hours. Return the number of employees who worked at least target hours, i.e. how many indices satisfy hours[i] >= target.

Inputhours = [0,1,2,3,4], target = 2
Output3
Employees with 2, 3 and 4 hours meet the target of 2; those with 0 and 1 do not. So the answer is 3.

def numberOfEmployeesWhoMetTarget(hours, target):
    count = 0                      # employees who met the target
    for h in hours:               # scan every employee's hours
        if h >= target:           # worked at least target hours?
            count += 1            # yes: include this employee
    return count                  # total that met the target
function numberOfEmployeesWhoMetTarget(hours, target) {
  let count = 0;                  // employees who met the target
  for (const h of hours) {        // scan every employee's hours
    if (h >= target) {            // worked at least target hours?
      count++;                    // yes: include this employee
    }
  }
  return count;                   // total that met the target
}
int numberOfEmployeesWhoMetTarget(int[] hours, int target) {
    int count = 0;                  // employees who met the target
    for (int h : hours) {           // scan every employee's hours
        if (h >= target) {          // worked at least target hours?
            count++;                // yes: include this employee
        }
    }
    return count;                   // total that met the target
}
int numberOfEmployeesWhoMetTarget(vector<int>& hours, int target) {
    int count = 0;                  // employees who met the target
    for (int h : hours) {           // scan every employee's hours
        if (h >= target) {          // worked at least target hours?
            count++;                // yes: include this employee
        }
    }
    return count;                   // total that met the target
}
Time: O(n) Space: O(1)