February 1

TopCoder – ThePhantomMenace

0  comments

Problem NameCompetitionDifficulty
ThePhantomMenaceSRM 678Easy

Solution

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.

thephantommenace

We can use LINQ also to calculate the maximum value.

thephantommenace2

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.

 


Tags


You may also like

The best way to stay up to date with C# 10 features

My Technical Journey from my first program to Lead Software Engineer

Top 10 C# Developer News from Microsoft Build 2020

Agile Estimation

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Subscribe to our newsletter now!

Get instant access to the Master C# 9 webinar to learn all the new exciting C# 9 features quickly.
Get regular videos and news on C# and .NET and offers on products and services to master C#.

We will collect, use and protect your data in accordance with our Privacy Policy.

>