Leetcode Problem 2010. The Number of Seniors and Juniors to Join the Company II
2010. The Number of Seniors and Juniors to Join the Company II
Leetcode Solutions
Cumulative Salary with Window Functions and Conditional Aggregation
Use a common table expression (CTE) or a subquery to calculate the cumulative salary for each candidate within their experience group using the SUM() OVER() window function.
Partition the candidates by their experience ('Senior' and 'Junior') and order them by their salary within each partition.
Create a CTE or subquery for seniors to select candidates whose cumulative salary is less than the budget.
Create a CTE or subquery for juniors to select candidates whose cumulative salary is less than the remaining budget after hiring seniors.
Use a UNION operation to combine the results from the seniors and juniors CTEs/subqueries.
Return the final list of employee IDs of the candidates to be hired.
erDiagram
Candidates {
int employee_id
enum experience
int salary
}