Problem Statement
You are given a
Definition
- Class:
- VolumeGuess
- Method:
- correctVolume
- Parameters:
- String[], int, int
- Returns:
- int
- Method signature:
- int correctVolume(String[] queries, int numberOfBoxes, int ithBox)
- (be sure your method is public)
Notes
- Keep in mind, the volume of the largest box is irrelevant.
Constraints
- numberOfBoxes will be between 3 and 9, inclusive.
- queries will contain exactly numberOfBoxes*(numberOfBoxes-1)/2 elements.
- Every element of queries will be in the given format ("box1,box2,volume", quotes for clarity).
- Each element of queries will contain between 5 and 50 characters, inclusive.
- Each box1 will be an integer between 1 and numberOfBoxes, inclusive, with possible leading zeros.
- Each box2 will be an integer between 1 and numberOfBoxes, inclusive, with possible leading zeros.
- Each volume will be an integer between 1 and 500, inclusive, with possible leading zeros.
- queries will contain no duplicates, that is, no pair of boxes will be compared twice.
- No two boxes will have the same volume.
- ithBox will be between 1 and numberOfBoxes, inclusive.
- The given data will be consistent.
- The box numbered ithBox will not be one of the two largest boxes.
Examples
{"1,2,10","1,3,10","2,3,20"}
3
1
Returns: 10
If box 1 has volume 10, box 2 has volume 20 and box 3 has volume 30, we get the given data. Another possibility is box 1 has volume 10, box 2 has volume 30 and box 3 has volume 20. Another is box 1 has volume 10, box 2 has volume 45 and box 3 has volume 20. There are many possibilities (infinite in fact). However, in all of them box 1 has to have size 10.
{"1,02,10","2,3,010","1,3,20"}
3
2
Returns: 10
If box 1 has volume 20, box 2 has volume 10 and box 3 has volume 30, we get the given data. (Note that leading zeros are allowed.)
{"1,2,31","1,3,9","1,4,31","2,4,32","3,4,9","3,2,9"}
4
1
Returns: 31
One possibility is box 1 has volume 31, box 2 has volume 50, box 3 has volume 9 and box 4 has volume 32.
{"1,2,31","1,3,9","1,4,31","2,4,32","3,4,9","3,2,9"}
4
3
Returns: 9
Same situation as above, but asks for a different ithbox.
{"3,2,80","5,2,15","1,2,193","3,1,80","5,1,15","5,3,15","3,4,3","4,5,3","2,4,3","4,1,3"}
5
3
Returns: 80
{"3,2,80","5,2,15","1,2,193","3,1,80","5,1,15","5,3,15","3,4,3","4,5,3","2,4,3","4,1,3"}
5
4
Returns: 3
{"3,2,80","5,2,15","1,2,193","3,1,80","5,1,15","5,3,15","3,4,3","4,5,3","2,4,3","4,1,3"}
5
5
Returns: 15
{"1,7,12", "2,1,12", "5,9,123", "7,6,100", "8,6,100", "6,9,100", "7,8,200", "1,5,12", "1,6,12", "1,8,12", "1,9,12", "2,3,34", "2,4,42", "3,7,34", "8,3,34", "9,3,34", "4,5,42", "4,6,42", "1,3,12", "1,4,12", "5,7,200", "5,8,300", "9,4,42", "5,6,100", "7,9,123", "8,9,123", "2,5,234", "2,6,100", "4,7,42", "4,8,42", "2,7,200", "8,2,234", "2,9,123", "3,4,34", "3,5,34", "3,6,34"}
9
1
Returns: 12
{"1,7,12", "2,1,12", "5,9,123", "7,6,100", "8,6,100", "6,9,100", "7,8,200", "1,5,12", "1,6,12", "1,8,12", "1,9,12", "2,3,34", "2,4,42", "3,7,34", "8,3,34", "9,3,34", "4,5,42", "4,6,42", "1,3,12", "1,4,12", "5,7,200", "5,8,300", "9,4,42", "5,6,100", "7,9,123", "8,9,123", "2,5,234", "2,6,100", "4,7,42", "4,8,42", "2,7,200", "8,2,234", "2,9,123", "3,4,34", "3,5,34", "3,6,34"}
9
2
Returns: 234
{"1,7,12", "2,1,12", "5,9,123", "7,6,100", "8,6,100", "6,9,100", "7,8,200", "1,5,12", "1,6,12", "1,8,12", "1,9,12", "2,3,34", "2,4,42", "3,7,34", "8,3,34", "9,3,34", "4,5,42", "4,6,42", "1,3,12", "1,4,12", "5,7,200", "5,8,300", "9,4,42", "5,6,100", "7,9,123", "8,9,123", "2,5,234", "2,6,100", "4,7,42", "4,8,42", "2,7,200", "8,2,234", "2,9,123", "3,4,34", "3,5,34", "3,6,34"}
9
3
Returns: 34
{"1,7,12", "2,1,12", "5,9,123", "7,6,100", "8,6,100", "6,9,100", "7,8,200", "1,5,12", "1,6,12", "1,8,12", "1,9,12", "2,3,34", "2,4,42", "3,7,34", "8,3,34", "9,3,34", "4,5,42", "4,6,42", "1,3,12", "1,4,12", "5,7,200", "5,8,300", "9,4,42", "5,6,100", "7,9,123", "8,9,123", "2,5,234", "2,6,100", "4,7,42", "4,8,42", "2,7,200", "8,2,234", "2,9,123", "3,4,34", "3,5,34", "3,6,34"}
9
4
Returns: 42
{"1,7,12", "2,1,12", "5,9,123", "7,6,100", "8,6,100", "6,9,100", "7,8,200", "1,5,12", "1,6,12", "1,8,12", "1,9,12", "2,3,34", "2,4,42", "3,7,34", "8,3,34", "9,3,34", "4,5,42", "4,6,42", "1,3,12", "1,4,12", "5,7,200", "5,8,300", "9,4,42", "5,6,100", "7,9,123", "8,9,123", "2,5,234", "2,6,100", "4,7,42", "4,8,42", "2,7,200", "8,2,234", "2,9,123", "3,4,34", "3,5,34", "3,6,34"}
9
6
Returns: 100
{"1,7,12", "2,1,12", "5,9,123", "7,6,100", "8,6,100", "6,9,100", "7,8,200", "1,5,12", "1,6,12", "1,8,12", "1,9,12", "2,3,34", "2,4,42", "3,7,34", "8,3,34", "9,3,34", "4,5,42", "4,6,42", "1,3,12", "1,4,12", "5,7,200", "5,8,300", "9,4,42", "5,6,100", "7,9,123", "8,9,123", "2,5,234", "2,6,100", "4,7,42", "4,8,42", "2,7,200", "8,2,234", "2,9,123", "3,4,34", "3,5,34", "3,6,34"}
9
7
Returns: 200
{"1,7,12", "2,1,12", "5,9,123", "7,6,100", "8,6,100", "6,9,100", "7,8,200", "1,5,12", "1,6,12", "1,8,12", "1,9,12", "2,3,34", "2,4,42", "3,7,34", "8,3,34", "9,3,34", "4,5,42", "4,6,42", "1,3,12", "1,4,12", "5,7,200", "5,8,300", "9,4,42", "5,6,100", "7,9,123", "8,9,123", "2,5,234", "2,6,100", "4,7,42", "4,8,42", "2,7,200", "8,2,234", "2,9,123", "3,4,34", "3,5,34", "3,6,34"}
9
9
Returns: 123
{"2,8,232", "4,8,234", "3,4,233", "3,5,233", "3,6,233", "3,7,233", "4,7,234", "1,2,231", "1,3,231", "5,6,235", "5,7,235", "5,8,235", "5,9,235", "6,7,236", "1,4,231", "1,5,231", "7,8,237", "4,9,234", "3,8,233", "3,9,233", "4,5,234", "4,6,234", "2,9,232", "7,9,237", "8,9,238", "1,8,231", "1,9,231", "2,3,232", "2,4,232", "2,5,232", "1,6,231", "1,7,231", "6,8,236", "6,9,236", "2,6,232", "2,7,232"}
9
1
Returns: 231
{"2,8,232", "4,8,234", "3,4,233", "3,5,233", "3,6,233", "3,7,233", "4,7,234", "1,2,231", "1,3,231", "5,6,235", "5,7,235", "5,8,235", "5,9,235", "6,7,236", "1,4,231", "1,5,231", "7,8,237", "4,9,234", "3,8,233", "3,9,233", "4,5,234", "4,6,234", "2,9,232", "7,9,237", "8,9,238", "1,8,231", "1,9,231", "2,3,232", "2,4,232", "2,5,232", "1,6,231", "1,7,231", "6,8,236", "6,9,236", "2,6,232", "2,7,232"}
9
2
Returns: 232
{"2,8,232", "4,8,234", "3,4,233", "3,5,233", "3,6,233", "3,7,233", "4,7,234", "1,2,231", "1,3,231", "5,6,235", "5,7,235", "5,8,235", "5,9,235", "6,7,236", "1,4,231", "1,5,231", "7,8,237", "4,9,234", "3,8,233", "3,9,233", "4,5,234", "4,6,234", "2,9,232", "7,9,237", "8,9,238", "1,8,231", "1,9,231", "2,3,232", "2,4,232", "2,5,232", "1,6,231", "1,7,231", "6,8,236", "6,9,236", "2,6,232", "2,7,232"}
9
3
Returns: 233
{"2,8,232", "4,8,234", "3,4,233", "3,5,233", "3,6,233", "3,7,233", "4,7,234", "1,2,231", "1,3,231", "5,6,235", "5,7,235", "5,8,235", "5,9,235", "6,7,236", "1,4,231", "1,5,231", "7,8,237", "4,9,234", "3,8,233", "3,9,233", "4,5,234", "4,6,234", "2,9,232", "7,9,237", "8,9,238", "1,8,231", "1,9,231", "2,3,232", "2,4,232", "2,5,232", "1,6,231", "1,7,231", "6,8,236", "6,9,236", "2,6,232", "2,7,232"}
9
4
Returns: 234
{"2,8,232", "4,8,234", "3,4,233", "3,5,233", "3,6,233", "3,7,233", "4,7,234", "1,2,231", "1,3,231", "5,6,235", "5,7,235", "5,8,235", "5,9,235", "6,7,236", "1,4,231", "1,5,231", "7,8,237", "4,9,234", "3,8,233", "3,9,233", "4,5,234", "4,6,234", "2,9,232", "7,9,237", "8,9,238", "1,8,231", "1,9,231", "2,3,232", "2,4,232", "2,5,232", "1,6,231", "1,7,231", "6,8,236", "6,9,236", "2,6,232", "2,7,232"}
9
5
Returns: 235
{"2,8,232", "4,8,234", "3,4,233", "3,5,233", "3,6,233", "3,7,233", "4,7,234", "1,2,231", "1,3,231", "5,6,235", "5,7,235", "5,8,235", "5,9,235", "6,7,236", "1,4,231", "1,5,231", "7,8,237", "4,9,234", "3,8,233", "3,9,233", "4,5,234", "4,6,234", "2,9,232", "7,9,237", "8,9,238", "1,8,231", "1,9,231", "2,3,232", "2,4,232", "2,5,232", "1,6,231", "1,7,231", "6,8,236", "6,9,236", "2,6,232", "2,7,232"}
9
6
Returns: 236
{"2,8,232", "4,8,234", "3,4,233", "3,5,233", "3,6,233", "3,7,233", "4,7,234", "1,2,231", "1,3,231", "5,6,235", "5,7,235", "5,8,235", "5,9,235", "6,7,236", "1,4,231", "1,5,231", "7,8,237", "4,9,234", "3,8,233", "3,9,233", "4,5,234", "4,6,234", "2,9,232", "7,9,237", "8,9,238", "1,8,231", "1,9,231", "2,3,232", "2,4,232", "2,5,232", "1,6,231", "1,7,231", "6,8,236", "6,9,236", "2,6,232", "2,7,232"}
9
7
Returns: 237
{"1,2,6", "1,3,45", "1,4,34", "1,5,23", "1,6,12", "1,7,7", "1,8,67", "1,9,67", "2,3,6", "2,4,6", "2,5,6", "2,6,6", "2,7,6", "2,8,6", "2,9,6", "3,4,34", "3,5,23", "3,6,12", "3,7,7", "3,8,45", "3,9,45", "4,5,23", "4,6,12", "4,7,7", "4,8,34", "4,9,34", "5,6,12", "5,7,7", "5,8,23", "5,9,23", "6,7,7", "6,8,12", "6,9,12", "7,8,7", "7,9,7", "8,9,85"}
9
1
Returns: 67
{"1,2,6", "1,3,45", "1,4,34", "1,5,23", "1,6,12", "1,7,7", "1,8,67", "1,9,67", "2,3,6", "2,4,6", "2,5,6", "2,6,6", "2,7,6", "2,8,6", "2,9,6", "3,4,34", "3,5,23", "3,6,12", "3,7,7", "3,8,45", "3,9,45", "4,5,23", "4,6,12", "4,7,7", "4,8,34", "4,9,34", "5,6,12", "5,7,7", "5,8,23", "5,9,23", "6,7,7", "6,8,12", "6,9,12", "7,8,7", "7,9,7", "8,9,85"}
9
2
Returns: 6
{"1,2,6", "1,3,45", "1,4,34", "1,5,23", "1,6,12", "1,7,7", "1,8,67", "1,9,67", "2,3,6", "2,4,6", "2,5,6", "2,6,6", "2,7,6", "2,8,6", "2,9,6", "3,4,34", "3,5,23", "3,6,12", "3,7,7", "3,8,45", "3,9,45", "4,5,23", "4,6,12", "4,7,7", "4,8,34", "4,9,34", "5,6,12", "5,7,7", "5,8,23", "5,9,23", "6,7,7", "6,8,12", "6,9,12", "7,8,7", "7,9,7", "8,9,85"}
9
3
Returns: 45
{"1,2,6", "1,3,45", "1,4,34", "1,5,23", "1,6,12", "1,7,7", "1,8,67", "1,9,67", "2,3,6", "2,4,6", "2,5,6", "2,6,6", "2,7,6", "2,8,6", "2,9,6", "3,4,34", "3,5,23", "3,6,12", "3,7,7", "3,8,45", "3,9,45", "4,5,23", "4,6,12", "4,7,7", "4,8,34", "4,9,34", "5,6,12", "5,7,7", "5,8,23", "5,9,23", "6,7,7", "6,8,12", "6,9,12", "7,8,7", "7,9,7", "8,9,85"}
9
4
Returns: 34
{"1,2,6", "1,3,45", "1,4,34", "1,5,23", "1,6,12", "1,7,7", "1,8,67", "1,9,67", "2,3,6", "2,4,6", "2,5,6", "2,6,6", "2,7,6", "2,8,6", "2,9,6", "3,4,34", "3,5,23", "3,6,12", "3,7,7", "3,8,45", "3,9,45", "4,5,23", "4,6,12", "4,7,7", "4,8,34", "4,9,34", "5,6,12", "5,7,7", "5,8,23", "5,9,23", "6,7,7", "6,8,12", "6,9,12", "7,8,7", "7,9,7", "8,9,85"}
9
5
Returns: 23
{"1,2,6", "1,3,45", "1,4,34", "1,5,23", "1,6,12", "1,7,7", "1,8,67", "1,9,67", "2,3,6", "2,4,6", "2,5,6", "2,6,6", "2,7,6", "2,8,6", "2,9,6", "3,4,34", "3,5,23", "3,6,12", "3,7,7", "3,8,45", "3,9,45", "4,5,23", "4,6,12", "4,7,7", "4,8,34", "4,9,34", "5,6,12", "5,7,7", "5,8,23", "5,9,23", "6,7,7", "6,8,12", "6,9,12", "7,8,7", "7,9,7", "8,9,85"}
9
6
Returns: 12
{"1,2,6", "1,3,45", "1,4,34", "1,5,23", "1,6,12", "1,7,7", "1,8,67", "1,9,67", "2,3,6", "2,4,6", "2,5,6", "2,6,6", "2,7,6", "2,8,6", "2,9,6", "3,4,34", "3,5,23", "3,6,12", "3,7,7", "3,8,45", "3,9,45", "4,5,23", "4,6,12", "4,7,7", "4,8,34", "4,9,34", "5,6,12", "5,7,7", "5,8,23", "5,9,23", "6,7,7", "6,8,12", "6,9,12", "7,8,7", "7,9,7", "8,9,85"}
9
7
Returns: 7
{"1,2,123", "1,3,123", "1,4,12", "1,5,123", "1,6,11", "1,7,13", "1,8,123", "1,9,1", "2,3,124", "2,4,12", "2,5,124", "2,6,11", "2,7,13", "2,8,124", "2,9,1", "3,4,12", "3,5,125", "3,6,11", "3,7,13", "3,8,125", "3,9,1", "4,5,12", "4,6,11", "4,7,12", "4,8,12", "4,9,1", "5,6,11", "5,7,13", "5,8,181", "5,9,1", "6,7,11", "6,8,11", "6,9,1", "7,8,13", "7,9,1", "8,9,1"}
9
1
Returns: 123
{"1,2,123", "1,3,123", "1,4,12", "1,5,123", "1,6,11", "1,7,13", "1,8,123", "1,9,1", "2,3,124", "2,4,12", "2,5,124", "2,6,11", "2,7,13", "2,8,124", "2,9,1", "3,4,12", "3,5,125", "3,6,11", "3,7,13", "3,8,125", "3,9,1", "4,5,12", "4,6,11", "4,7,12", "4,8,12", "4,9,1", "5,6,11", "5,7,13", "5,8,181", "5,9,1", "6,7,11", "6,8,11", "6,9,1", "7,8,13", "7,9,1", "8,9,1"}
9
2
Returns: 124
{"1,2,123", "1,3,123", "1,4,12", "1,5,123", "1,6,11", "1,7,13", "1,8,123", "1,9,1", "2,3,124", "2,4,12", "2,5,124", "2,6,11", "2,7,13", "2,8,124", "2,9,1", "3,4,12", "3,5,125", "3,6,11", "3,7,13", "3,8,125", "3,9,1", "4,5,12", "4,6,11", "4,7,12", "4,8,12", "4,9,1", "5,6,11", "5,7,13", "5,8,181", "5,9,1", "6,7,11", "6,8,11", "6,9,1", "7,8,13", "7,9,1", "8,9,1"}
9
3
Returns: 125
{"1,2,123", "1,3,123", "1,4,12", "1,5,123", "1,6,11", "1,7,13", "1,8,123", "1,9,1", "2,3,124", "2,4,12", "2,5,124", "2,6,11", "2,7,13", "2,8,124", "2,9,1", "3,4,12", "3,5,125", "3,6,11", "3,7,13", "3,8,125", "3,9,1", "4,5,12", "4,6,11", "4,7,12", "4,8,12", "4,9,1", "5,6,11", "5,7,13", "5,8,181", "5,9,1", "6,7,11", "6,8,11", "6,9,1", "7,8,13", "7,9,1", "8,9,1"}
9
4
Returns: 12
{"1,2,123", "1,3,123", "1,4,12", "1,5,123", "1,6,11", "1,7,13", "1,8,123", "1,9,1", "2,3,124", "2,4,12", "2,5,124", "2,6,11", "2,7,13", "2,8,124", "2,9,1", "3,4,12", "3,5,125", "3,6,11", "3,7,13", "3,8,125", "3,9,1", "4,5,12", "4,6,11", "4,7,12", "4,8,12", "4,9,1", "5,6,11", "5,7,13", "5,8,181", "5,9,1", "6,7,11", "6,8,11", "6,9,1", "7,8,13", "7,9,1", "8,9,1"}
9
6
Returns: 11
{"1,2,123", "1,3,123", "1,4,12", "1,5,123", "1,6,11", "1,7,13", "1,8,123", "1,9,1", "2,3,124", "2,4,12", "2,5,124", "2,6,11", "2,7,13", "2,8,124", "2,9,1", "3,4,12", "3,5,125", "3,6,11", "3,7,13", "3,8,125", "3,9,1", "4,5,12", "4,6,11", "4,7,12", "4,8,12", "4,9,1", "5,6,11", "5,7,13", "5,8,181", "5,9,1", "6,7,11", "6,8,11", "6,9,1", "7,8,13", "7,9,1", "8,9,1"}
9
7
Returns: 13
{"1,2,123", "1,3,123", "1,4,12", "1,5,123", "1,6,11", "1,7,13", "1,8,123", "1,9,1", "2,3,124", "2,4,12", "2,5,124", "2,6,11", "2,7,13", "2,8,124", "2,9,1", "3,4,12", "3,5,125", "3,6,11", "3,7,13", "3,8,125", "3,9,1", "4,5,12", "4,6,11", "4,7,12", "4,8,12", "4,9,1", "5,6,11", "5,7,13", "5,8,181", "5,9,1", "6,7,11", "6,8,11", "6,9,1", "7,8,13", "7,9,1", "8,9,1"}
9
9
Returns: 1
{ "1,2,8", "1,3,7", "1,4,6", "1,5,5", "1,6,4", "1,7,3", "1,8,2", "1,9,1", "2,3,7", "2,4,6", "2,5,5", "2,6,4", "2,7,3", "2,8,2", "2,9,1", "3,4,6", "3,5,5", "3,6,4", "3,7,3", "3,8,2", "3,9,1", "4,5,5", "4,6,4", "4,7,3", "4,8,2", "4,9,1", "5,6,4", "5,7,3", "5,8,2", "5,9,1", "6,7,3", "6,8,2", "6,9,1", "7,8,2", "7,9,1", "8,9,1" }
9
3
Returns: 7
{ "1,3,9", "1,2,31", "1,4,31", "2,4,32", "3,4,9", "3,2,9" }
4
1
Returns: 31
{ "2,3,20", "2,1,10", "3,1,10" }
3
1
Returns: 10
{ "1,2,20", "1,3,10", "2,3,10" }
3
3
Returns: 10
{ "1,2,5", "1,3,10", "1,4,10", "2,3,5", "2,4,5", "3,4,20" }
4
1
Returns: 10
{ "1,02,10", "2,3,010", "1,3,20" }
3
2
Returns: 10
{ "1,4,380", "2,4,250", "3,4,140", "1,2,250", "1,3,140", "3,2,140" }
4
2
Returns: 250
{ "1,2,31", "1,4,31", "1,3,9", "2,4,32", "3,4,9", "3,2,9" }
4
1
Returns: 31
{ "2,1,10", "3,1,10", "2,3,20" }
3
1
Returns: 10
{ "1,2,266", "1,3,95", "1,4,30", "1,5,191", "2,3,95", "2,4,30", "2,5,191", "3,4,30", "3,5,95", "4,5,30" }
5
3
Returns: 95
{ "4,1,10", "4,2,10", "4,3,10", "3,1,20", "3,2,20", "2,1,30" }
4
3
Returns: 20
{ "1,4,15", "3,4,20", "1,3,15", "3,2,10", "2,4,10", "1,2,10" }
4
1
Returns: 15
{ "1,2,10", "1,3,10", "1,4,10", "2,3,20", "2,4,20", "3,4,30" }
4
2
Returns: 20