Problem Statement
The products will be given in a
compete = {"1 4", "2", "3", "0", ""}The example above shows product 0 competes with 1 and 4, product 1 competes with 2, product 2 competes with 3, and product 3 competes with 0. Note, competition is symmetric so product 1 competing with product 2 means product 2 competes with product 1 as well.
Ways to market:
1) 0 to Teenagers, 1 to Adults, 2 to Teenagers, 3 to Adults, and 4 to Adults
2) 0 to Adults, 1 to Teenagers, 2 to Adults, 3 to Teenagers, and 4 to Teenagers
Your method would return 2.
Definition
- Class:
- Marketing
- Method:
- howMany
- Parameters:
- String[]
- Returns:
- long
- Method signature:
- long howMany(String[] compete)
- (be sure your method is public)
Constraints
- compete will contain between 1 and 30 elements, inclusive.
- Each element of compete will have between 0 and 50 characters, inclusive.
- Each element of compete will be a single space delimited sequence of integers such that: All of the integers are unique.Each integer contains no extra leading zeros.Each integer is between 0 and k-1 inclusive where k is the number of elements in compete.
- No element of compete contains leading or trailing whitespace.
- Element i of compete will not contain the value i.
- If i occurs in the jth element of compete, j will not occur in the ith element of compete.
Examples
{"1 4","2","3","0",""}
Returns: 2
The example from above.
{"1","2","0"}
Returns: -1
Product 0 cannot be marketed with product 1 or 2. Product 1 cannot be marketed with product 2. There is no way to achieve a viable marketing scheme.
{"1","2","3","0","0 5","1"}
Returns: 2
{"","","","","","","","","","", "","","","","","","","","","", "","","","","","","","","",""}
Returns: 1073741824
{"1","2","3","4","5","6","7","8","9","10","11","12","13","14",""}
Returns: 2
{"1","2","3","0","5","6","4"}
Returns: -1
{"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18", "19","20","21","22","23","24","25","26","27","28","29","0"}
Returns: 2
{"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18", "19","20","21","22","23","24","25","26","27","28","29","5"}
Returns: -1
{"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18", "19","20","21","22","23","24","25","26","27","28","29","6"}
Returns: 2
{"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18", "19","20","21","22","23","24","25","26","27","28","29","6 8 10 12 14 16 18 20"}
Returns: 2
{"1 2 3 4","","","","","1 7","2 8","3","4","10","11","12","13","14","9"}
Returns: -1
{"1 2 3 4","","","","","1 15","2 15","3 15","4 15","10","11","12","13","14","9",""}
Returns: 4
{"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "7 8 9 10 11 12 13 14 15 16 17 18 19 20", "8 9 10 11 12 13 14 15 16 17 18 19 20", "9 10 11 12 13 14 15 16 17 18 19 20", "10 11 12 13 14 15 16 17 18 19 20", "11 12 13 14 15 16 17 18 19 20", "12 13 14 15 16 17 18 19 20", "13 14 15 16 17 18 19 20", "14 15 16 17 18 19 20", "15 16 17 18 19 20", "16 17 18 19 20", "17 18 19 20", "18 19 20", "19 20", "20", "","","","","" }
Returns: -1
{"1 2", "3 4","5 6", "7 8","9 10","11 12","13 14", "15 16","17 18","19 20","21 22","23 24","24 25","25 26","27 28", "29","29","29","29","29","29","29","29","29","29","29","29","29","29",""}
Returns: 2
{"1 2", "3 4","5 6", "7 8","9 10","11 12","13 14", "15 16","17 18","19 20","21 22","23 24","24 25","25 26","27 28", "29","29","29","29","29","29","29","29","29","29","29","29","29","29", "0 3 4 5 6"}
Returns: 2
{"1 2 4","5 3","3 6","7","5 6","7","7",""}
Returns: 2
{"1 2 4","5 3","3 6","7","5 6","7","7","","","", "11 12 14","15 13","13 16","17","15 16","17","17","","","","","","","",""}
Returns: 2048
{ "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27", "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27", "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27", "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27", "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27", "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27", "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27", "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27", "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27", "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27", "11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27", "","","","","","","","","","","","","","","","","","",""}
Returns: 8
{ "1 6 7","7 2","8 3","9 4","10 5","11", "7 12","13 8","14 9","15 10","16 11","17", "13 18","14 19","20 15","16 21","17 22","23", "24 19","25 20","26 21","27 22","28 23","29", "25","26","27","28","29",""}
Returns: -1
{ "1 6","7 2","8 3","9 4","10 5","11", "7 12","13 8","14 9","15 10","16 11","17", "13 18","14 19","20 15","16 21","17 22","23", "24 19","25 20","26 21","27 22","28 23","29", "25","26","27","28","29",""}
Returns: 2
{ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "5", "", "", "10", "", "", "", "", "", "", "", "", "", "" }
Returns: 67108864
{ "", "7", "9", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }
Returns: 268435456
{ "", "", "0 1" }
Returns: 2
{ "1", "2", "3", "1" }
Returns: -1
{ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }
Returns: 1073741824
{ "1", "2", "3", "4", "0" }
Returns: -1
{ "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "29", "" }
Returns: 2
{ "1", "2", "" }
Returns: 2
{ "1", "", "1" }
Returns: 2