Problem Statement | |||||||||||||
A sum rectangle is a rectangle divided into a grid of unit squares. Each square contains a number, and the numbers in neighboring squares always satisfy the following property: The number in any square S that is neither in the bottom row nor in the right column can be computed as the sum of the following three numbers:
An example of a correctly filled sum rectangle: +----+----+----+----+----+ | 88 | 57 | 33 | 10 | 5 | +----+----+----+----+----+ | 18 | 13 | 11 | 12 | -7 | +----+----+----+----+----+ | 1 | 4 | -2 | 1 | 18 | +----+----+----+----+----+ For example, in the top left corner we have 88 = 18 + 57 + 13. We have a secret sum rectangle. You will be given a int[] leftColumn containing the leftmost number in each row of our rectangle, from the top to the bottom. You will also be given an int[] topRow containing the topmost number in each column of our rectangle, from the left to the right. Compute and return the number in the bottom right corner. If the input is such that this number cannot be determined uniquely, return 0 instead. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
- | You may assume that the return value will always fit into an int (i.e., a 32-bit signed integer data type). | ||||||||||||
Constraints | |||||||||||||
- | leftColumn will contain between 1 and 10 elements, inclusive. | ||||||||||||
- | Each element of leftColumn will be between 0 and 100, inclusive. | ||||||||||||
- | topRow will contain between 1 and 10 elements, inclusive. | ||||||||||||
- | Each element of topRow will be between 0 and 100, inclusive. | ||||||||||||
- | Element 0 of leftColumn will be equal to element 0 of topRow. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
|