Here is my brute force solution to the Problem : Solution

I am able to understand all the approaches mentioned on gfg O(nlog n) time and O(n) time but I cannot understand the brute force one. So I have tried it and I am getting WA. Then I found that their own Brute force code is also giving WA. Kindly someone help me in pointing out where I am wrong.

In your approach you are counting the number of platforms on the basis of trains which have overlapping schedules with the ith train but this can be higher than the actual number of platforms required.

Consider this if there are 5 trains whose timing does not overlap with each other but overlaps with one other train then according to your approach answer will be 6 but actual answer will be 2 as all those trains will take 1 platform and the current train will take 1 platform.

1 Like

@lotthbrok Thank you for replying. I got you point very well. In that case I think the brute force solution mentioned in the gfg editorial is wrong .Can you then tell me what can be the brute force approach to it? I am asking it in case I have to point it in the interview. I cannot directly jump into the O(nlogn) one.

You need to sort the arrays on the basis of departure times then apply the same method that you applied above.

Regarding interviews, if you know an optimized solution of a problem it is okay to jump to it if you can clearly explain it to the interviewer rather than wasting time on naive solutions, it can help to save time which can be utilized on further questions which you may be solving for the first time.

Thank you @lotthbrok . I got it.