Number of Employees Who Met the Target - Problem

Imagine you're a HR manager at a tech company reviewing employee performance! ๐Ÿ“Š

You have n employees numbered from 0 to n-1, and each employee i has worked for hours[i] hours this quarter. Your company has a minimum requirement that each employee must work at least target hours to meet their performance goal.

Given a 0-indexed array hours of length n containing non-negative integers representing hours worked by each employee, and a non-negative integer target representing the minimum required hours, your task is to determine how many employees have met or exceeded the target.

Goal: Return the count of employees who worked at least target hours.

Example: If hours = [0, 1, 2, 3, 4] and target = 2, then employees with indices 2, 3, and 4 have worked โ‰ฅ 2 hours, so the answer is 3.

Input & Output

example_1.py โ€” Basic Case
$ Input: hours = [0,1,2,3,4], target = 2
โ€บ Output: 3
๐Ÿ’ก Note: Employees at indices 2, 3, and 4 worked 2, 3, and 4 hours respectively, all meeting the target of 2 hours. Employees 0 and 1 worked 0 and 1 hours, which are below the target.
example_2.py โ€” All Employees Meet Target
$ Input: hours = [5,1,4,2,2], target = 1
โ€บ Output: 5
๐Ÿ’ก Note: All employees worked at least 1 hour (5โ‰ฅ1, 1โ‰ฅ1, 4โ‰ฅ1, 2โ‰ฅ1, 2โ‰ฅ1), so all 5 employees meet the target.
example_3.py โ€” No Employees Meet Target
$ Input: hours = [1,2,3], target = 5
โ€บ Output: 0
๐Ÿ’ก Note: None of the employees worked 5 or more hours (1<5, 2<5, 3<5), so 0 employees meet the target.

Visualization

Tap to expand
Employee Performance Review Process๐Ÿ‘จโ€๐Ÿ’ผHR Manager๐Ÿ“‹0h๐Ÿ“‹1h๐Ÿ“‹2h๐Ÿ“‹3h๐Ÿ“‹4hEmployee TimesheetsTarget: 2 hours๐ŸŽฏPerformance Goal1. Review Each2. Compare Hours3. Count Qualified4. Final CountโŒ Employee 0: 0 < 2 hoursโŒ Employee 1: 1 < 2 hoursโœ… Employee 2: 2 โ‰ฅ 2 hoursโœ… Employee 3: 3 โ‰ฅ 2 hoursโœ… Employee 4: 4 โ‰ฅ 2 hoursPerformance Report3employees met targetLinear scan: O(n) time, O(1) space - optimal solution!
Understanding the Visualization
1
Prepare Timesheets
Gather all employee hour records and set the performance target
2
Review Each Employee
Go through each timesheet and compare hours worked vs target
3
Mark Qualifying Employees
Count employees who meet or exceed the target hours
4
Generate Report
Return the total count of employees who met the performance goal
Key Takeaway
๐ŸŽฏ Key Insight: Since we need to examine every employee to get an accurate count, a simple linear scan is the optimal approach with O(n) time complexity.

Time & Space Complexity

Time Complexity
โฑ๏ธ
O(n)

We must examine each of the n employees exactly once

n
2n
โœ“ Linear Growth
Space Complexity
O(1)

Only using a constant amount of extra space for the counter

n
2n
โœ“ Linear Space

Constraints

  • 1 โ‰ค n โ‰ค 50
  • 0 โ‰ค hours[i], target โ‰ค 105
  • hours.length equals the number of employees
Asked in
Amazon 25 Google 18 Microsoft 12 Meta 8
28.4K Views
Medium Frequency
~5 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen