TopCoder – ThePhantomMenace

Problem Name Competition Difficulty
ThePhantomMenace SRM 678 Easy


Full source code is available here.

To solve the problem, we need to calculate the safety level for each door and then return the maximum.

To calculate the safety level of a door, we need to get the positive distance between each drone and the door and take the minimum value.

The description above can be expressed in code quite easily.


We can use LINQ also to calculate the maximum value.


Personal Notes

Remember that Max() and Min() throw an exception if the collection is empty.

It is very important to read carefully the constraints section of the problem description. 

This was not a problem for this exercise because the doors and droids arrays will always contain between 1 and 10 elements.


Sharing is Caring