Hackerblocks (Cover Them All!)

https://hack.codingblocks.com/app/practice/3/p/1148
getting TLE in one of the test case. Please help.

Hey @dishask99
Your solution has N^2 time complexity so it works on small test cases perfectly. But it’ll give TLE for large test cases. The question has an NlogN solution based on sorting of soldiers position on X axis. Think in that direction.

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.

@dishask99
https://ide.codingblocks.com/s/180994 You can check this out. Please mark your doubt as resolved if you are satisfied

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.

But this is giving TLE for 3 test cases