Problem Statement
The length of a jump between two stones of coordinates (x1,y1) and (x2,y2) is defined as the Euclidian distance:
sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))
You will be given a int[] x and a int[] y with exactly 2 elements each, representing the coordinates of the stones: (x[i],y[i]) is the location of the i-th stone. The edge of the shore on which you initially stand has an x-value of 0 and could take any y-value. Thus, the minimal distance between the shore and the first stone you jump on is the x-value in the location of that stone. The edge of the other shore has an x-value of 10 and could take any y-value as well.
Return the distance of the longest jump you need to make, rounded to the nearest integer.
Definition
- Class:
- SwimmersDelight
- Method:
- longestJump
- Parameters:
- int[], int[]
- Returns:
- int
- Method signature:
- int longestJump(int[] x, int[] y)
- (be sure your method is public)
Notes
- You may jump on the 2 stones in any order, or just on one stone.
Constraints
- x and y will each contain 2 elements.
- All values in x are between 1 and 9, inclusive.
- All values in y are between 0 and 10, inclusive.
- The two stones are not in the same location.
- No actual distance will be more than 1e-4 close to some integer + 0.5.
Examples
{3,7}
{5,5}
Returns: 4
The three stones are arranged in a line, so the strategy is quite simple here: you first jump on the stone at (3,5), then on the stone at (7,5) and you finally reach the other shore at (10,5). The longest jump has a length of 4 feet: from (3,5) to (7,5). If you like to play around, you can follow the path (0,5) - (7,5) - (3,5) - (10,5), but this is not optimal since you have to make a jump of 7 feet! Thus, the correct answer is 4.
{3,6}
{5,2}
Returns: 4
The path you should take is (0,5) - (3,5) - (6,2) - (10,2). Between (3,5) and (6,2) there is a distance of sqrt(3*3 + 3*3) = 4.2426. There are no jumps longer than this and because the answer is rounded to the nearest integer, you should return 4.
{1,1}
{4,6}
Returns: 9
If you can jump 9 feet at once, chances are you are also a good swimmer ...
{3,8}
{0,10}
Returns: 7
Only the stone at (3,0) is used in this case. The stone at (8,10) is more than 7 feet away from both the shore and the stone at (3,0).
{4,2}
{5,5}
Returns: 6
The river can be a good initiation in the triple-jump technique. But you can also skip the stone at (2,5), as you need to take a 6 feet jump anyway.
{9,1}
{0,6}
Returns: 9
{5,8}
{4,10}
Returns: 5
{1,1}
{9,6}
Returns: 9
{2,8}
{7,5}
Returns: 6
{2,4}
{9,3}
Returns: 6
{7,2}
{6,2}
Returns: 6
{9,7}
{7,10}
Returns: 7
{4,9}
{8,0}
Returns: 6
{6,6}
{1,7}
Returns: 6
{8,8}
{0,3}
Returns: 8
{9,2}
{7,2}
Returns: 8
{9,3}
{7,0}
Returns: 7
{8,7}
{8,0}
Returns: 7
{5,8}
{8,4}
Returns: 5
{9,9}
{1,2}
Returns: 9
{6,9}
{1,7}
Returns: 6
{2,4}
{1,0}
Returns: 6
{2,4}
{4,2}
Returns: 6
{8,4}
{7,4}
Returns: 5
{9,7}
{2,4}
Returns: 7
{9,5}
{1,4}
Returns: 5
{1,9}
{3,3}
Returns: 8
{5,3}
{4,2}
Returns: 5
{2,2}
{3,6}
Returns: 8
{4,5}
{3,8}
Returns: 5
{2,8}
{3,3}
Returns: 6
{1,4}
{0,2}
Returns: 6
{5,8}
{8,4}
Returns: 5
{2,1}
{10,1}
Returns: 8
{4,6}
{5,3}
Returns: 4
{9,6}
{4,3}
Returns: 6
{3,5}
{9,4}
Returns: 5
{8,5}
{8,1}
Returns: 5
{8,1}
{1,10}
Returns: 8
{7,2}
{9,2}
Returns: 7
{6,6}
{6,1}
Returns: 6
{6,6}
{0,3}
Returns: 6
{5,3}
{7,3}
Returns: 5
{7,7}
{0,7}
Returns: 7
{3,4}
{3,4}
Returns: 6
{2,9}
{2,2}
Returns: 7
{1,6}
{10,3}
Returns: 6
{4,5}
{2,8}
Returns: 5
{8,9}
{3,4}
Returns: 8
{5,8}
{3,10}
Returns: 5
{3,2}
{4,7}
Returns: 7
{3,3}
{6,10}
Returns: 7
{2,8}
{1,7}
Returns: 8
{1,5}
{2,7}
Returns: 5
{3,8}
{9,10}
Returns: 5
{1,9}
{8,5}
Returns: 9
{6,9}
{2,1}
Returns: 6
{7,7}
{5,7}
Returns: 7
{1,4}
{5,3}
Returns: 6
{3,4}
{6,10}
Returns: 6
{8,4}
{10,1}
Returns: 6
{1,4}
{5,3}
Returns: 6
{7,1}
{2,1}
Returns: 6
{8,3}
{7,7}
Returns: 5
{5,2}
{5,8}
Returns: 5
{7,9}
{9,2}
Returns: 7
{7,9}
{10,2}
Returns: 7
{6,3}
{2,1}
Returns: 4
{1,9}
{4,7}
Returns: 9
{1,1}
{8,3}
Returns: 9
{5,8}
{6,8}
Returns: 5
{8,4}
{2,8}
Returns: 6
{8,4}
{7,0}
Returns: 6
{6,6}
{9,5}
Returns: 6
{2,9}
{10,1}
Returns: 8
{2,9}
{0,5}
Returns: 8
{2,9}
{7,1}
Returns: 8
{5,5}
{6,2}
Returns: 5
{7,4}
{3,1}
Returns: 4
{8,1}
{4,8}
Returns: 8
{2,1}
{0,5}
Returns: 8
{8,1}
{6,3}
Returns: 8
{4,5}
{4,10}
Returns: 5
{8,2}
{1,8}
Returns: 8
{4,9}
{3,9}
Returns: 6
{4,4}
{5,8}
Returns: 6
{1,4}
{10,2}
Returns: 6
{8,4}
{3,7}
Returns: 6
{8,5}
{10,6}
Returns: 5
{6,1}
{6,2}
Returns: 6
{4,4}
{1,7}
Returns: 6
{7,6}
{0,2}
Returns: 6
{2,9}
{4,1}
Returns: 8
{7,4}
{10,6}
Returns: 5
{2,7}
{9,7}
Returns: 5
{8,9}
{6,9}
Returns: 8
{6,6}
{4,9}
Returns: 6
{3, 8 }
{0, 10 }
Returns: 7
{2, 7 }
{10, 0 }
Returns: 7
{5, 5 }
{1, 9 }
Returns: 5
{1, 6 }
{1, 4 }
Returns: 6
{3, 5 }
{0, 9 }
Returns: 5
{7, 8 }
{1, 9 }
Returns: 7
{1, 7 }
{1, 4 }
Returns: 7
{5, 1 }
{10, 0 }
Returns: 5
{1, 3 }
{0, 10 }
Returns: 7
{7, 3 }
{0, 10 }
Returns: 7
{1, 5 }
{0, 10 }
Returns: 5
{7, 3 }
{0, 0 }
Returns: 4
{1, 9 }
{1, 9 }
Returns: 9
{1, 8 }
{0, 0 }
Returns: 7
{8, 1 }
{1, 10 }
Returns: 8
{6, 3 }
{1, 1 }
Returns: 4
{2, 8 }
{4, 6 }
Returns: 6
{9, 1 }
{5, 5 }
Returns: 8
{9, 8 }
{5, 5 }
Returns: 8
{1, 5 }
{1, 10 }
Returns: 5
{8, 2 }
{3, 3 }
Returns: 6
{8, 9 }
{0, 9 }
Returns: 8
{4, 8 }
{8, 4 }
Returns: 6
{3, 9 }
{5, 2 }
Returns: 7
{8, 6 }
{5, 5 }
Returns: 6
{3, 5 }
{7, 1 }
Returns: 5
{1, 8 }
{0, 10 }
Returns: 8
{5, 5 }
{0, 10 }
Returns: 5