Given four arrays of integers and an integer limit. We need to pick 1 number from each of the four arrays such that the sum of the selected numbers is smaller or equal to limit. Find the number of valid combinations.
Example
Input:
a = [2, 3, 5]
b = [5]
c = [2, 3, 10]
d = [1, 2]
limit = 11
Output: 4
We can pick the numbers in the following four ways: [2, 5, 2, 1], [2, 5, 3, 1], [2, 5, 2, 2], [3, 5, 2, 1]. So return 4.