LeetCode 2798: Number of Employees Who Met the Target Solution

Master LeetCode problem 2798 (Number of Employees Who Met the Target), a easy challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

2798. Number of Employees Who Met the Target

Easy

Problem Explanation

Explanation:

To solve this problem, we iterate through the hours array and count the number of employees who worked at least target hours. We can simply check if the current number of hours is greater than or equal to the target and increment a counter variable. At the end, we return the counter as the result.

  • Time complexity: O(n) where n is the number of employees
  • Space complexity: O(1)

Solution Code

class Solution {
    public int numOfEmployees(int[] hours, int target) {
        int count = 0;
        for (int i = 0; i < hours.length; i++) {
            if (hours[i] >= target) {
                count++;
            }
        }
        return count;
    }
}

Try It Yourself

Loading code editor...

Related LeetCode Problems

Frequently Asked Questions

How to solve LeetCode 2798 (Number of Employees Who Met the Target)?

This page provides optimized solutions for LeetCode problem 2798 (Number of Employees Who Met the Target) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 2798 (Number of Employees Who Met the Target)?

The time complexity for LeetCode 2798 (Number of Employees Who Met the Target) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 2798 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 2798 in Java, C++, or Python.

Back to LeetCode Solutions