Problem Statement
Create a class Regions that contains the method numTaxes that takes
Definition
- Class:
- Regions
- Method:
- numTaxes
- Parameters:
- int[], int[]
- Returns:
- int
- Method signature:
- int numTaxes(int[] row, int[] col)
- (be sure your method is public)
Notes
- We are not charged a tax if we just touch the boundary of a region.
Constraints
- rows has between 1 and 50 elements inclusive.
- columns has the same number of elements as rows.
- Each element of rows and or columns is between 0 and 1,000,000,000 inclusive.
Examples
{4,2,3}
{4,2,6}
Returns: 7
Going from the center of 4,4 to the center of 2,2 we pay tax when we enter region 3,3 and when we enter region 2,2. Going from the center of 2,2 to the center of 3,6 we pay tax as we enter 2,3 then 2,4 then 3,4 then 3,5 then 3,6.
{0,1000000000,0}
{0,1000000000,0}
Returns: 2000000000
We enter each region along the diagonal on the first leg, a total of 1,000,000,000 regions. On the way back we go back down the diagonal but we still have to pay taxes.
{0,10,10}
{0,2,2}
Returns: 10
The first leg enters (1,0),(2,0),(3,1),(4,1),(5,1),(6,1),(7,1),(8,2),(9,2),(10,2). The second leg just stays within region (10,2), paying no additional taxes.
{9,0}
{0,9}
Returns: 9
{0,9}
{0,9}
Returns: 9
{0,9}
{0,1}
Returns: 9
{0,1000000000,6}
{0,999999999,18}
Returns: -1
Each of the two legs enters almost 2 billion regions, so the sum of the taxes along this path is greater than 2 billion.
{1000,100000,100000}
{0,100000,1000000000}
Returns: 1000099000
{1000,100000,100000}
{0,101000,1000000000}
Returns: 1000098000
{1,2,3,4,5,6,7,8,9,8,7,7}
{100,200,300,400,500,600,700,800,900,900,900,901}
Returns: 811
{1000,100000,100000}
{0,100999,1000000000}
Returns: 1000099000
{1,2,3,4,5,6,7,8,9,8,7,7}
{100,200,300,400,500,600,700,800,900,900,900,900}
Returns: 810
{100,200,300,400,500,600,700,800,900,900,900,900}
{1,2,3,4,5,6,7,8,9,8,7,7}
Returns: 810
{1,1,1}
{999999999,999999999,999999999}
Returns: 0
{1,1,1}
{999999999,1,999999999}
Returns: 1999999996
{1,1,1,1}
{999999999,1,999999999,2}
Returns: -1
{999999999,1,999999999,999999999}
{1,1,1,5}
Returns: 2000000000
{999999999,1,999999999,999999999}
{1,1,1,6}
Returns: -1
{345111111,100234567,123456,654321}
{251435123,412345123,341235643,123123123}
Returns: 795650520
{ 0, 1000000000, 6 }
{ 0, 999999999, 18 }
Returns: -1
{ 4, 2, 3 }
{ 4, 2, 6 }
Returns: 7
{ 0, 10, 10 }
{ 0, 2, 2 }
Returns: 10
{ 55, 455, 86, 500, 500, 333, 444, 5, 834, 5, 999, 55, 455, 86, 500, 500, 333, 444, 5, 834, 5, 999, 5, 834, 5, 999, 55, 455, 500, 444, 456, 19, 300, 55, 89, 33, 100, 1, 2, 3, 4, 5, 6, 7, 866, 56, 111, 48, 444 }
{ 43, 9, 86, 500, 500, 333, 333, 994, 934, 22, 82, 55, 455, 86, 500, 500, 333, 444, 5, 834, 5, 999, 4, 934, 22, 82, 55, 455, 99, 1000, 1, 2, 3, 4, 5, 99, 455, 333, 698, 453, 756, 243, 567, 44, 12, 15, 16, 88, 1000 }
Returns: 29428
{ 0, 2, 0, 1, 1, 3 }
{ 0, 2, 2, 0, 1, 30000 }
Returns: 30009
{ 5, 9 }
{ 6, 10 }
Returns: 4
{ 0, 2 }
{ 0, 10 }
Returns: 10
{ 0, 100000000 }
{ 0, 100000000 }
Returns: 100000000
{ 0, 50 }
{ 0, 38 }
Returns: 86
{ 321654987, 326598741, 1354689, 321654987, 12326547, 6546313, 6587313, 513847, 1681, 654987333, 1, 2 }
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 2, 321654 }
Returns: -1
{ 0, 3 }
{ 0, 5 }
Returns: 7
{ 0, 4 }
{ 0, 6 }
Returns: 10
{ 0, 1000000000, 0, 1000000000, 0, 1000000000, 0, 1000000000, 0, 1000000000 }
{ 0, 1000000000, 0, 1000000000, 0, 1000000000, 0, 1000000000, 0, 1000000000 }
Returns: -1
{ 321, 3, 21, 18, 4, 7, 11, 13, 16, 79 }
{ 0, 2, 7, 11115, 12, 14, 19, 1, 7, 6 }
Returns: 22673
{ 1, 2 }
{ 1, 6 }
Returns: 5
{ 0, 6 }
{ 0, 20 }
Returns: 26
{ 0, 1, 2, 3, 4, 5, 34543, 4343, 345345, 6747, 7436, 436, 34 }
{ 0, 2, 5, 9, 14, 20, 23478, 3245, 765, 64250, 64250, 3245, 34 }
Returns: 926322
{ 4, 2, 3, 0, 10, 10 }
{ 4, 2, 6, 0, 2, 2 }
Returns: 26
{ 0, 2, 777777700 }
{ 0, 4, 777777700 }
Returns: 1555555400
{ 0, 65536 }
{ 0, 65536 }
Returns: 65536
{ 0, 1 }
{ 0, 1 }
Returns: 1
{ 0, 1000000000, 0, 100000000, 0, 100000000, 0, 9999999, 0, 99999992, 3, 99999994, 9873, 5186, 1873, 18438, 112 }
{ 1000000000, 0, 1000000000, 0, 1000000000, 0, 1000000000, 0, 1000000000, 0, 1000000000, 6548, 153, 4831, 13, 23, 4 }
Returns: -1
{ 0, 4 }
{ 0, 2 }
Returns: 6
{ 0, 5 }
{ 0, 7 }
Returns: 11
{ 42, 532553, 42424 }
{ 242424, 525, 777 }
Returns: 1264784
{ 0, 2 }
{ 0, 4 }
Returns: 6
{ 99999999, 0 }
{ 99999997, 0 }
Returns: 199999995