TopCoder problem "SpeedRadar" used in TCHS SRM 1 (Division I Level One)



Problem Statement

    

A speed radar is installed in a highway zone where the maximum speed limit is maxLimit mph, and the minimum speed limit is minLimit mph. Any reading that is strictly above or below this interval is an infringement.

Periodically, the radar readings are analyzed to make sure that the sensors are working properly. It is assumed that most drivers obey speed limits, and therefore, the radar will be considered faulty if more than 10% of its readings are infringements.

Given the radar readings over a period of time, return the average speed of all cars that are driving within the speed limits. If the radar is faulty, return 0.0.

 

Definition

    
Class:SpeedRadar
Method:averageSpeed
Parameters:int, int, int[]
Returns:double
Method signature:double averageSpeed(int minLimit, int maxLimit, int[] readings)
(be sure your method is public)
    
 

Notes

-The returned value must be accurate to within a relative or absolute value of 1E-9.
 

Constraints

-maxLimit will be between 1 and 200, inclusive.
-minLimit will be between 1 and maxLimit, inclusive.
-readings will contain between 1 and 50 elements, inclusive.
-Each element of readings will be between 1 and 200, inclusive.
 

Examples

0)
    
1
50
{45, 40, 50}
Returns: 45.0
With all drivers within the speed limits, the return value is just the average speed.
1)
    
1
50
{42,43,44,45,46,47,48,49,50,51}
Returns: 46.0
There is only one driver infringing the limit, and it represents 10% of the total readings. The average speed of the other readings is 46.0.
2)
    
1
50
{42,46,48,50,52}
Returns: 0.0
Only one reading is outside the given limits, but it represents 20% of the total number of readings. We therefore assume that the radar is not working and return 0.0.
3)
    
20
60
{25,45,45,43,24,9,51,55,60,34,61,23,40,40,47,49,33,23,47,54,54}
Returns: 41.68421052631579

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6474

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10022&pm=6474

Writer:

ged

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Simple Math, Simple Search, Iteration