Problem Statement | |||||||||||||
A 100 meter long pipe must be cut in two places. It can only be cut at certain places, where it was originally welded from smaller pipes. If the two cut locations are chosen at random (each potential location has equal probability of being chosen), find the probability of a resulting pipe being longer than L meters.
Create a method named probability that accepts a int[] weldLocations and int L as parameters. It should calculate the probability of one or more resulting pipes being strictly longer than L if the two cut locations are chosen at random from weldLocations. Each element in weldLocations represents the number of meters from the left end of the pipe. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
- | Your return value must have a relative or absolute error less than 1e-9. | ||||||||||||
Constraints | |||||||||||||
- | weldLocations will have between 2 and 50 elements, inclusive. | ||||||||||||
- | Each element in weldLocations will be between 1 and 99, inclusive. | ||||||||||||
- | weldLocations will not contain duplicate elements. | ||||||||||||
- | L will be between 1 and 100, inclusive. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
|