i did it using priority queues but
please tell how it can be done using sorting algo as i am not able to frame it
Please share the solution
Hello @harryson see this code:
Basically we have to compute the maximum number of active halls for the given start and end times on the basis of overlapping time periods.
1.Maintain two arrays namely start[ ] and end[ ] with start and end times by splitting the in[ ][ ] input array.
2.Sort the two arrays maintained in step1.
3.Initialize two variables i and j i.e start index and end index to 0.
4.Initialize two more variables c(Active party halls at instant) and max(maximum number of active halls needed) to 0. 5.If start[i] or start time < end[i] or end time, i.e we have overlapping time periods hence we have a party active. So increment c i.e active party halls and increment start index i.
6.Else time periods are not overlapping so decrement c and increment end index j.
7.Now compute the maximum between c and max to record the max number of active halls.
8.Return max.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.