Problem Statement: There are $n$ hours in a day and you have $w$ workers workers. For For each worker $i$ you will be given $\mathit{xp}$$x_i$ (work experience), $s$ $s_i$ (shift start time) and $e$$e_i$ (shift end time) on a separate line. Here Here $s$$s_i$ and $e$$e_i$ are both inclusive. At At any given hour $t$ in a day day, you have to determine who is the most experienced worker available.
I thought of two approaches:
Keep an interval array of size $n$. For For each worker $i$, from index $s$ $s_i$ to $e$$e_i$ of the array, fill it with $\mathit{xp}$$x_i$ if current value in the the array is lesser. This This is memory intensive.
Store $[\mathit{xp}, s, e]$$\left( x_i, s_i, e_i \right)$ for each worker $i$ in a list. Loop Loop through the list for every $t$ provided to find the most experienced experienced person. This This is CPU intensive.
I want to know which data structure can be used to solve this problem optimally optimally.