Premium problem114. Peak Headcount During Each Tenure

Hard Locked

employees has columns employee_id, hire_date and termination_date (both datetime; a still-employed person has NaT).

For every employee, find the largest number of people employed at the same time on any day during their own tenure, and the first date that peak occurred. Return a DataFrame with columns employee_id, peak_headcount and peak_date, sorted by employee_id with the index renumbered from 0.

Somebody's termination date is their last day gone, not worked: treat them as active from hire_date up to but not including termination_date.

Input

   employee_id  hire_date termination_date
0            1 2021-01-01       2021-01-06
1            2 2021-01-03       2021-01-10
2            3 2021-01-05              NaT

Output

   employee_id  peak_headcount  peak_date
0            1               3 2021-01-05
1            2               3 2021-01-05
2            3               3 2021-01-05

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)