LeetCode in Kotlin

2798. Number of Employees Who Met the Target

Easy

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.

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.

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.

Constraints:

Solution

class Solution {
    fun numberOfEmployeesWhoMetTarget(hours: IntArray, target: Int): Int {
        var count = 0
        for (i in hours) {
            if (i >= target) {
                count++
            }
        }
        return count
    }
}