Leetcode 2798: Number of Employees Who Met the Target

grid47
grid47
Exploring patterns and algorithms
Feb 1, 2024 4 min read

You are given an array ‘hours’ where each element represents the number of hours an employee has worked at the company. The company requires each employee to work for at least ’target’ hours. Your task is to return the number of employees who worked at least ’target’ hours.
Problem
Approach
Steps
Complexity
Input: You are given a 0-indexed array 'hours' representing the hours worked by employees and a non-negative integer 'target'.
Example: Input: hours = [0, 1, 3, 5, 7], target = 3
Constraints:
• 1 <= n == hours.length <= 50
• 0 <= hours[i], target <= 10^5
Output: Return the number of employees who have worked at least 'target' hours.
Example: Output: 3
Constraints:
Goal: To determine how many employees worked at least the target number of hours.
Steps:
• Iterate through the array of hours.
• For each employee, check if their worked hours are greater than or equal to the target.
• Count the employees who meet the target hours.
Goal: Ensure that the solution adheres to the given constraints.
Steps:
• 1 <= n == hours.length <= 50
• 0 <= hours[i], target <= 10^5
Assumptions:
• The input array contains non-negative integers.
• The number of employees is small enough to allow a straightforward solution.
Input: Input: hours = [0, 1, 3, 5, 7], target = 3
Explanation: Here, the company wants employees to work for at least 3 hours. Employees with hours >= 3 are employee 2, 3, and 4, so the output is 3.

Input: Input: hours = [4, 2, 1, 6], target = 5
Explanation: Here, the company wants employees to work for at least 5 hours. Only employee 3 worked 6 hours, so the output is 1.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus