The Number of Seniors and Juniors to Join the Company - Problem

A company wants to hire new employees with a budget of $70,000 for salaries. The hiring criteria are:

  • First priority: Hire the largest number of seniors possible
  • Second priority: Use the remaining budget to hire the largest number of juniors

Given a table of candidates with their experience level and salary, determine how many seniors and juniors can be hired under these constraints.

The result should show the count of each experience level that can be hired within budget.

Table Schema

Candidates
Column Name Type Description
employee_id PK int Unique identifier for each candidate
experience enum Experience level: 'Senior' or 'Junior'
salary int Monthly salary requirement
Primary Key: employee_id
Note: Each row represents a candidate with their salary requirements and experience level

Input & Output

Example 1 — Basic Hiring Scenario
Input Table:
employee_id experience salary
1 Senior 10000
2 Junior 10000
3 Senior 20000
4 Junior 30000
Output:
experience accepted_candidates
Senior 2
Junior 1
💡 Note:

With a $70,000 budget: First, hire seniors by salary order: Senior 1 ($10,000) + Senior 3 ($20,000) = $30,000. Remaining budget: $40,000. Then hire juniors: Junior 2 ($10,000) fits, but Junior 4 ($30,000) would exceed remaining budget. Total: 2 seniors + 1 junior.

Example 2 — All Seniors Exceed Budget
Input Table:
employee_id experience salary
1 Senior 80000
2 Junior 10000
3 Junior 20000
Output:
experience accepted_candidates
Senior 0
Junior 2
💡 Note:

No seniors can be hired as the cheapest senior costs $80,000, exceeding the $70,000 budget. Full budget goes to juniors: Junior 2 ($10,000) + Junior 3 ($20,000) = $30,000. Total: 0 seniors + 2 juniors.

Example 3 — Only Seniors Hired
Input Table:
employee_id experience salary
1 Senior 20000
2 Senior 30000
3 Junior 50000
Output:
experience accepted_candidates
Senior 2
Junior 0
💡 Note:

Hire seniors first: Senior 1 ($20,000) + Senior 2 ($30,000) = $50,000. Remaining budget: $20,000. Junior 3 costs $50,000, which exceeds the remaining budget. Total: 2 seniors + 0 juniors.

Constraints

  • 1 ≤ employee_id ≤ 1000
  • experience is either 'Senior' or 'Junior'
  • 1 ≤ salary ≤ 100000
  • The company's budget is exactly $70000

Visualization

Tap to expand
Budget-Based Hiring StrategyCandidates Poolidexperiencesalary1Senior100002Junior100003Senior200004Junior30000Budget: $70,0001. Hire Seniors FirstSenior 1: $10k ✓Senior 3: $20k ✓Remaining: $40kHired CountexperiencecountSenior2Junior1Strategy: Greedy Selection by Priority1. Sort seniors by salary (ascending)2. Hire maximum seniors within budget3. Use remaining budget for juniors
Understanding the Visualization
1
Input
Candidates with salary and experience
2
Process
Greedy selection by experience priority
3
Output
Count of hired candidates by experience
Key Takeaway
🎯 Key Insight: Use greedy selection with priority-based budget allocation to maximize hiring within constraints
Asked in
Amazon 23 Microsoft 18 Google 15
28.5K Views
Medium Frequency
~18 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