here is the code which i wrote please debugg my code
Please tell why my code is not passing any test cases
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.