Problem Statement
Given the additional connections that were formed, your method will determine the minimum number of connections that need be removed such that there will not be any crossings. Note that, given a particular set of connections, if it is possible to lay the wires such that they will not cross, the people will do so. This means the people may change their locations and how much wire they use in order to remove crossings. They will not succeed if a crossing is inevitable. Also, since the base network must not be damaged, the removed connections cannot include any of the base network connections.
You will be given 2
Definition
- Class:
- TelephoneGame
- Method:
- howMany
- Parameters:
- int[], int[], int
- Returns:
- int
- Method signature:
- int howMany(int[] connect1, int[] connect2, int numPeople)
- (be sure your method is public)
Notes
- Without loss of generality, you can assume that the people are arranged in a circular pattern. Continuing this image, the base network would be seen from a helicopter as a circle.
Constraints
- connect1 must contain between 1 and 18 elements inclusive
- connect1 must contain the same number of elements as connect2
- numPeople must be between 4 and 10000 inclusive
- Element i of connect1 will not be equal to element i of connect2
- Each element of connect1 and connect2 will be between 0 and numPeople-1 inclusive
- There will be no repeated connections. In other words, if a connection from a to b exists, there will be no other connections of the form a to b or b to a allowed as input. This includes the original connections, so there will be no connections from i to i+1, or from 0 to the last person.
Examples
{0,0,0,1,1,2}
{2,3,4,3,4,4}
10000
Returns: 1
{0,9,19,29,39,49,59,69}
{10,20,30,40,50,60,70,5}
100
Returns: 0
{0,0,0,0,0,1,1,1,1,2,2,2,3,3,3,4,4}
{3,4,5,6,7,4,5,6,7,5,6,7,5,6,7,6,7}
100
Returns: 6
{2,3,4,5,3,4,5,4,5,5}
{0,0,0,0,1,1,1,2,2,3}
10000
Returns: 3
{2,3,4,5,6,3,4,5,6,4,5,6,5,6,6}
{0,0,0,0,0,1,1,1,1,2,2,2,3,3,4}
1000
Returns: 6
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18}
{2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,20}
100
Returns: 0
{0,1}
{2,3}
4
Returns: 0
The given connections can easily be formed without crossings as depicted below: _______ / | 0---1 / | /| / | / | / |/ |/ 3---2
{4,4,4,5,5,6}
{6,7,8,7,8,8}
10
Returns: 1
There is no way for all of these connections to be added without a crossing.
{0,2,4}
{3,5,1}
6
Returns: 1
{37,29,1,57,98,72,10,32,41,94,93,18,70,84,82,73,23,69}
{69,91,26,6,65,92,6,25,85,58,74,39,21,91,80,53,30,3}
100
Returns: 6
{29,46,63,52,45,19,62,17,62,9,41,70,50,39,71,18,14,80}
{85,52,94,61,32,76,4,22,18,22,48,87,25,67,37,22,19,64}
100
Returns: 4
{43,0,25,43,84,95,38,30,27,54,5,19,75,20,40,43,88,63}
{14,24,99,11,5,27,12,16,80,69,80,85,83,83,5,1,49,30}
100
Returns: 6
{68,33,35,25,89,72,92,26,28,84,37,39,96,47,5,42,78,81}
{30,50,73,22,14,21,80,8,89,51,35,66,64,63,22,28,87,67}
100
Returns: 5
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18}
{2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,20}
100
Returns: 0
{83,10,49,41,85,97,75,4,90,75,87,1,57,50,36,17,97,35}
{28,28,5,24,36,37,30,84,18,88,32,53,7,43,32,60,41,19}
100
Returns: 8
{84,82,49,50,18,77,29,10,71,44,51,58,20,72,40,9,12,64}
{12,8,31,52,93,29,55,0,26,17,42,49,23,25,68,84,44,81}
100
Returns: 4
{79,50,28,3,42,44,43,93,55,41,62,22,74,22,95,55,27,50}
{33,3,84,60,90,98,12,51,38,14,20,14,60,54,22,4,50,9}
100
Returns: 7
{33,75,10,87,77,84,13,84,18,89,26,12,87,8,10,80,88,73}
{29,16,66,22,66,73,36,8,29,93,6,28,0,59,68,62,10,2}
100
Returns: 4
{52,63,7,40,71,27,83,99,79,55,25,71,4,53,45,91,22,72}
{36,80,35,9,8,47,30,52,16,24,18,29,90,87,78,31,77,41}
100
Returns: 7
{8,77,73,62,21,36,66,38,79,68,4,70,21,35,26,34,1,80}
{59,15,28,0,50,7,14,59,43,90,61,3,96,10,21,99,62,62}
100
Returns: 7
{3,78,85,99,14,35,55,96,84,16,81,74,16,27,41,39,93,43}
{40,70,1,60,24,94,3,69,80,92,45,85,7,17,82,56,60,60}
100
Returns: 5
{12,76,65,61,28,42,97,26,33,84,76,5,94,39,83,61,46,79}
{89,54,59,69,58,4,33,47,14,74,70,71,4,37,37,2,22,63}
100
Returns: 6
{23,66,36,60,68,51,13,32,30,23,25,62,72,97,22,91,80,35}
{32,75,49,92,44,41,54,84,53,15,1,91,16,44,7,50,14,70}
100
Returns: 6
{54,91,75,57,79,51,84,13,64,3,14,69,45,76,70,62,77,9}
{85,21,24,31,41,86,90,11,73,83,31,66,91,98,7,92,36,68}
100
Returns: 5
{96,47,94,79,27,54,89,72,44,6,32,25,59,48,76,97,55,90}
{41,87,41,14,44,22,1,99,22,35,44,28,97,83,61,93,38,65}
100
Returns: 4
{34,7,1,82,46,4,91,37,47,34,86,48,64,36,18,58,39,95}
{0,9,60,71,19,14,48,96,26,26,32,65,85,27,28,36,3,91}
100
Returns: 5
{8,24,90,79,73,51,14,5,73,56,71,58,11,42,16,63,87,85}
{71,31,16,49,55,36,74,3,77,89,6,37,69,56,84,71,46,40}
100
Returns: 5
{60,86,11,52,75,73,24,17,90,50,31,28,62,51,66,54,82,31}
{6,51,20,78,83,75,83,7,28,71,82,97,26,12,8,64,35,21}
100
Returns: 6
{24,57,56,59,95,28,39,4,29,75,97,7,61,48,82,84,92,82}
{77,45,34,86,6,21,45,86,94,47,94,30,63,62,94,20,5,39}
100
Returns: 4
{94,5,13,14,23,18,37,71,84,59,99,60,80,85,29,94,86,23}
{6,45,52,81,37,72,85,38,69,49,22,95,83,52,18,66,57,4}
100
Returns: 6
{78,43,46,7,65,13,28,97,35,86,92,68,63,25,32,83,63,73}
{27,7,53,74,70,20,59,8,33,8,81,37,61,81,55,41,53,51}
100
Returns: 2
{32,28,56,99,96,78,97,51,32,94,81,62,15,79,67,50,17,5}
{51,14,5,17,35,36,50,63,36,90,62,36,53,94,45,71,23,72}
100
Returns: 5
{43,6,87,79,69,58,32,84,21,71,16,80,2,38,72,68,76,21}
{57,54,32,45,20,23,4,68,65,97,36,68,73,76,45,58,79,24}
100
Returns: 6
{81,95,1,77,93,28,42,70,55,98,21,81,18,56,53,91,39,28}
{83,39,54,28,51,25,6,0,61,80,59,58,39,62,62,63,48,0}
100
Returns: 3
{18,88,66,27,54,80,14,25,95,5,25,70,18,40,48,30,6,84}
{12,75,20,12,61,72,30,36,63,99,27,60,0,95,6,10,2,52}
100
Returns: 2
{67,78,19,96,24,77,71,9,75,10,69,32,47,2,13,15,30,62}
{58,2,87,28,50,26,89,4,87,42,71,99,77,7,45,28,33,26}
100
Returns: 6
{36,96,49,4,21,16,63,76,46,1,14,35,15,46,49,5,39,59}
{1,53,98,18,70,75,96,63,71,71,26,70,23,70,51,9,55,51}
100
Returns: 3
{4,61,93,59,24,96,94,12,92,46,67,3,79,85,80,65,54,73}
{27,3,83,56,19,74,27,82,87,52,30,76,51,76,16,15,69,18}
100
Returns: 5
{36,65,28,79,8,63,92,37,81,32,61,38,80,94,60,29,59,29}
{25,96,6,92,40,53,69,26,2,22,11,51,25,37,92,54,81,61}
100
Returns: 7
{57,15,64,31,29,7,73,5,49,40,57,5,83,50,66,59,88,53}
{64,9,7,77,57,60,63,51,35,92,18,53,20,46,53,3,70,82}
100
Returns: 5
{95,14,18,55,71,49,11,76,26,98,48,93,34,18,43,19,36,63}
{78,0,16,74,31,84,2,5,0,76,11,95,23,80,16,73,67,17}
100
Returns: 3
{45,7,51,30,50,2,72,17,90,75,47,61,54,65,93,45,98,76}
{15,21,99,6,59,39,0,95,48,33,45,51,89,53,77,67,9,41}
100
Returns: 6
{77,67,4,38,40,0,5,17,90,21,25,81,45,23,19,9,60,16}
{56,62,18,95,15,4,2,80,28,76,49,31,6,43,3,18,63,29}
100
Returns: 6
{43,7,9,21,36,16,71,81,84,79,32,41,35,21,57,79,92,46}
{27,91,39,33,58,74,64,28,67,19,35,28,88,28,35,62,35,29}
100
Returns: 5
{36,52,49,53,61,35,22,85,59,19,74,72,80,28,14,58,91,69}
{25,50,91,5,92,97,91,81,37,50,84,92,91,59,2,1,6,29}
100
Returns: 4
{90,12,87,21,24,39,11,70,5,79,73,17,35,67,99,14,63,45}
{30,81,82,53,11,65,75,22,60,22,43,0,80,50,87,70,16,32}
100
Returns: 6
{49,47,21,62,46,68,17,59,55,27,91,53,60,87,97,47,94,99}
{66,65,2,90,1,60,52,72,19,67,81,49,10,52,29,73,1,74}
100
Returns: 6
{71,11,8,14,7,11,78,5,25,88,53,58,51,10,11,52,0,15}
{28,36,25,40,48,8,59,56,1,25,19,20,97,51,45,6,91,46}
100
Returns: 6
{45,6,16,93,55,54,90,37,35,93,48,87,97,54,11,15,72,37}
{67,57,12,61,40,73,14,31,21,73,76,79,44,85,19,35,51,1}
100
Returns: 4
{0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1}
{2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,20}
1000
Returns: 0
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17}
{30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47}
1000
Returns: 16