Skip to main content
Use $x$ instead of mathit{xp}
Source Link
John Kemeny
  • 17.1k
  • 3
  • 43
  • 67

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:

  1. 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.

  2. 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.

Problem Statement: There are $n$ hours in a day and you have $w$ workers. For each worker you will be given $\mathit{xp}$ (work experience), $s$ (shift start time) and $e$ (shift end time) on a separate line. Here $s$ and $e$ are both inclusive. At any given hour $t$ in a day, you have to determine who is the most experienced worker available.

I thought of two approaches:

  1. Keep an interval array of size $n$. For each worker, from index $s$ to $e$ of the array, fill it with $\mathit{xp}$ if current value in the array is lesser. This is memory intensive.

  2. Store $[\mathit{xp}, s, e]$ for each worker in a list. Loop through the list for every $t$ provided to find the most experienced person. This is CPU intensive.

I want to know which data structure can be used to solve this problem optimally.

Problem Statement: There are $n$ hours in a day and you have $w$ workers. For each worker $i$ you will be given $x_i$ (work experience), $s_i$ (shift start time) and $e_i$ (shift end time) on a separate line. Here $s_i$ and $e_i$ are both inclusive. At any given hour $t$ in a day, you have to determine who is the most experienced worker available.

I thought of two approaches:

  1. Keep an interval array of size $n$. For each worker $i$, from index $s_i$ to $e_i$ of the array, fill it with $x_i$ if current value in the array is lesser. This is memory intensive.

  2. Store $\left( x_i, s_i, e_i \right)$ for each worker $i$ in a list. Loop through the list for every $t$ provided to find the most experienced person. This is CPU intensive.

I want to know which data structure can be used to solve this problem optimally.

added 34 characters in body
Source Link
Yuval Filmus
  • 279.1k
  • 27
  • 316
  • 512

Problem Statement: There are 'n'$n$ hours in a day and you have 'w'$w$ workers. For each worker you will be given 'xp' $\mathit{xp}$ (work experience), 's' $s$ (shift start time) and 'e' $e$ (shift end time) on a separate line. Here 's'$s$ and 'e'$e$ are both inclusive. At any given hour 't'$t$ in a day, you have to determine who is the most experienced worker available.

I thought of 2two approaches

a) Keep an interval array of size n. For each worker, from index 's' to 'e' of the array, fill it with 'xp' if current value in the array is lesser. This is memory intensive.:

b) Store [xp, s, e] for each worker in a list. Loop through the list for every 't' provided to find the most experienced person. This is CPU intensive.

  1. Keep an interval array of size $n$. For each worker, from index $s$ to $e$ of the array, fill it with $\mathit{xp}$ if current value in the array is lesser. This is memory intensive.

  2. Store $[\mathit{xp}, s, e]$ for each worker in a list. Loop through the list for every $t$ provided to find the most experienced person. This is CPU intensive.

I want to know which data structure can be used to solve this problem optimally.

Problem Statement: There are 'n' hours in a day and you have 'w' workers. For each worker you will be given 'xp' (work experience), 's' (shift start time) and 'e' (shift end time) on a separate line. Here 's' and 'e' are both inclusive. At any given hour 't' in a day, you have to determine who is the most experienced worker available.

I thought of 2 approaches

a) Keep an interval array of size n. For each worker, from index 's' to 'e' of the array, fill it with 'xp' if current value in the array is lesser. This is memory intensive.

b) Store [xp, s, e] for each worker in a list. Loop through the list for every 't' provided to find the most experienced person. This is CPU intensive.

I want to know which data structure can be used to solve this problem optimally.

Problem Statement: There are $n$ hours in a day and you have $w$ workers. For each worker you will be given $\mathit{xp}$ (work experience), $s$ (shift start time) and $e$ (shift end time) on a separate line. Here $s$ and $e$ are both inclusive. At any given hour $t$ in a day, you have to determine who is the most experienced worker available.

I thought of two approaches:

  1. Keep an interval array of size $n$. For each worker, from index $s$ to $e$ of the array, fill it with $\mathit{xp}$ if current value in the array is lesser. This is memory intensive.

  2. Store $[\mathit{xp}, s, e]$ for each worker in a list. Loop through the list for every $t$ provided to find the most experienced person. This is CPU intensive.

I want to know which data structure can be used to solve this problem optimally.

Source Link

Which data structure can be used to determine most experienced person in a shift?

Problem Statement: There are 'n' hours in a day and you have 'w' workers. For each worker you will be given 'xp' (work experience), 's' (shift start time) and 'e' (shift end time) on a separate line. Here 's' and 'e' are both inclusive. At any given hour 't' in a day, you have to determine who is the most experienced worker available.

I thought of 2 approaches

a) Keep an interval array of size n. For each worker, from index 's' to 'e' of the array, fill it with 'xp' if current value in the array is lesser. This is memory intensive.

b) Store [xp, s, e] for each worker in a list. Loop through the list for every 't' provided to find the most experienced person. This is CPU intensive.

I want to know which data structure can be used to solve this problem optimally.