Problem Statement | |||||||||||||
Suppose the solution to some problem is a set of integers, several of which you do not know. You wish to evaluate the nearness of some candidate set of known integers to the solution. For example, the candidate solution might be {9, 1, 2, 3, 5, 6}, while the target is {4, 9, 2, 1}: actually six integers, but two are unknown. We define the distance between a target and a candidate to be the minimum sum of absolute differences in known values, disregarding extraneous candidate values. Here the distance would be |4-3| + |9-9| + |2-2| + |1-1| = 1: we have ignored the 5 and 6. Given a int[] target and a int[] candidate, return the distance between them. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | candidate will contain between 1 and 20 elements, inclusive. | ||||||||||||
- | target will contain between 1 and 20 elements, inclusive. | ||||||||||||
- | target will not contain more elements than candidate. | ||||||||||||
- | Each element of target and candidate will be between -1000 and 1000, inclusive. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
|