FAANG Party Hall Problem

Hi,
In this problem’'s solution video the example was taken as the sorted values for both start and end times. So it was not affecting the pair as the pair would be the same after both of sorting. But if in case if we sort both the start and end time array which are not already sorted then it will not mismatch the start and end time pairing. e.g. [{0,30} , {5,10},{15,20}] after sorting this will be like [{0,10},{5,20},{15,30}] will this not affect the algorithm. I have checked this is not but can anyone explain WHY this is not affecting ?

Your goal is just to find the maximum number of parties at a given time. So what you can do is either pick a time and check for each range if that time falls in the range. If it falls, you increase your counter. And you do this for each time and get the final answer.
I will explain my approach with an example. Let the time ranges be -
(0,2), (1,5), (2,4), (4,6)
Answer here should be 3
Create a pair vector as follows ->
(0,2) -> (0,0), (2,1)
(1,5) -> (1,0), (5,1)
(2,4) -> (2,0), (4,1)
(4,6) -> (4,0), (6,1)

Now sort the 8 values obtained using inbuilt sort function. And initialize a variable as 0. When v[i].second=0, it means a party has started so increment your counter. In the other case, a party has ended, so decrement it.
(0,0) (1,0) (2,0) (2,1) (4,0) (4,1) (5,1) (6,1)
1 2 3 2 3 2 1 0

Maximum value of counter is 3. So we need minimum 3 party halls.

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.