Problem Statement
Write a class Swimmers with a method getSwimTimes which takes a
Definition
- Class:
- Swimmers
- Method:
- getSwimTimes
- Parameters:
- int[], int[], int
- Returns:
- int[]
- Method signature:
- int[] getSwimTimes(int[] distances, int[] speeds, int current)
- (be sure your method is public)
Constraints
- distances contains between 0 and 50 elements, inclusive
- each element of distances will be between 0 and 10000, inclusive
- speeds will have the same number of elements as distances
- each element of speeds will be between 0 and 100, inclusive
- current will be between 0 and 100, inclusive
Examples
{ 300, 300, 300 }
{ 1, 2, 3 }
2
Returns: { -1, -1, 360 }
The current is 2 meters per second, and each swimmer is going to swim 300 meters with the current followed by 300 meters back to their starting point. The first swimmer only swims at 1 meter per second, so it will be impossible to return to the starting point. The second swimmer matches the speed of the current, but will never be able to travel the return trip. The third swimmer swims at 3 meters per second, so will travel the 300 meters at 5 meters per second with the current and 1 meter per second against the current. This results in 60 seconds for the downstream trip and 300 seconds for the upstream trip, for a total of 360 seconds.
{ 500, 500 }
{ 4, 5 }
2
Returns: { 333, 238 }
The first swimmer travels 500 meters downstream at 6 meters/second, resulting in 83 and 1/3 seconds. The upstream trip is done at 2 meters/second and takes 250 seconds. This results in a total time of 333 and 1/3 seconds. The integer portion of this is 333 seconds. The second swimmer travels 500 meters downstream at 7 meters/sec and takes 71 and 3/7 seconds. The upstream trip is done at 3 meters/second and takes 166 and 2/3 seconds. This results in 238 and 2/21 seconds. The integer portion of this is 238 seconds.
{ 0, 0 }
{ 1, 2 }
1
Returns: { 0, 0 }
All the swimmers are swimming a distance of 0 meters, so it takes 0 seconds to finish.
{ 0, 1 }
{ 0, 0 }
0
Returns: { 0, -1 }
Watch out for division by zero!
{ 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919 }
{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 99, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 51 }
6
Returns: { -1, -1, -1, 8108, 1950, 1474, 1014, 882, 705, 544, 507, 420, 377, 359, 328, 290, 260, 252, 229, 216, 210, 195, 185, 173, 159, 155, -1, -1, 4409, 2413, 1717, 1354, 1127, 969, 852, 764, 692, 635, 585, 543, 507, 476, 449, 424, 402, 383, 365, 349, 334, 314 }
{ 10000, 10000, 10000 }
{ 17, 19, 24 }
11
Returns: { 2023, 1583, 1054 }
{ 9999, 9999, 9999, 1234 }
{ 50, 100, 85, 12 }
4
Returns: { 402, 200, 235, 231 }
{ 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 500 }
{ 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90 }
10
Returns: { 202, 183, 164, 145, 126, 106, 86, 65, 43, 22, 11 }
{ 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000, 500 }
{ 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90 }
8
Returns: { 201, 183, 164, 145, 125, 106, 85, 64, 43, 22, 11 }
{ 1234, 2468, 3691, 4816, 5101, 6122, 7142, 8163, 9183 }
{ 12, 24, 36, 48, 51, 61, 71, 81, 91 }
1
Returns: { 207, 206, 205, 200, 200, 200, 201, 201, 201 }
{ 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192 }
{ 2, 4, 8, 16, 32, 64, 100, 63, 31, 15, 7, 3, 1 }
1
Returns: { 2, 2, 2, 2, 2, 2, 2, 8, 33, 137, 597, 3072, -1 }
{ 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192 }
{ 2, 4, 8, 16, 32, 64, 100, 63, 31, 15, 7, 3, 1 }
1
Returns: { 2, 2, 2, 2, 2, 2, 2, 8, 33, 137, 597, 3072, -1 }
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
14
Returns: { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15 }
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
6
Returns: { -1, -1, -1, -1, -1, -1, 7, 4, 3, 3, 2, 2, 2, 2, 2 }
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
2
Returns: { -1, -1, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
1
Returns: { -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }
{ 500, 500 }
{ 4, 5 }
2
Returns: { 333, 238 }
{ 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919 }
{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 99, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 51 }
6
Returns: { -1, -1, -1, 8108, 1950, 1474, 1014, 882, 705, 544, 507, 420, 377, 359, 328, 290, 260, 252, 229, 216, 210, 195, 185, 173, 159, 155, -1, -1, 4409, 2413, 1717, 1354, 1127, 969, 852, 764, 692, 635, 585, 543, 507, 476, 449, 424, 402, 383, 365, 349, 334, 314 }
{ 20 }
{ 3 }
0
Returns: { 13 }
{ 0, 0 }
{ 1, 2 }
1
Returns: { 0, 0 }
{ 0, 0, 0 }
{ 3, 2, 1 }
2
Returns: { 0, 0, 0 }
{ 0, 1 }
{ 0, 0 }
0
Returns: { 0, -1 }
{ 300, 300, 300 }
{ 1, 2, 3 }
2
Returns: { -1, -1, 360 }
{ 0 }
{ 1 }
10
Returns: { 0 }
{ }
{ }
5
Returns: { }
{ 0 }
{ 1 }
4
Returns: { 0 }
{ 0, 0, 0 }
{ 0, 1, 2 }
1
Returns: { 0, 0, 0 }
{ 500, 500 }
{ 4, 5 }
6
Returns: { -1, -1 }
{ 0 }
{ 0 }
0
Returns: { 0 }
{ 1, 1 }
{ 3, 3 }
0
Returns: { 0, 0 }
{ 5 }
{ 3 }
1
Returns: { 3 }