Imagine this scene, Your boss wants to know how long you spend time in front of your laptop between 2 p.m and 3 p.m. However, you may leave to have a snack or buy a cup of coffee. Is there a good algorithm or data structure to efficiently get the "working period" as accurately as possible? Some complicated situations I want to solve listed below.
- I leave at 1:59 p.m and come back at 2:03 p.m, thus I spent 3 minutes in front of my laptop.
- I leave at 2:59 p.m and come back(or never come back) at 3:03 p.m, thus I only spent 1 minute in front of my laptop between 2 p.m and 3 p.m.