You have to arrays of single digit numbers. (0 - 9).
A = [....1 billion elements....];
B = [3,5,8,1,2,5,8,3,4,9,1,0,2];
I want to find combo of as few as possible subsets that of array B in A.
So whole Array B could be in Array A by coincidence since it's very large and that would be the largest match as whole sequence is there. Or you could have subset of array B, [8,3,4,9]
, at index ex: i = 3800443
...
Now my goal is to convert Array B to references based on Array A.
So If I give you object like this:
{
block1: {i: 48938, len: 388},
block2: {i: 2828, len: 3},
...
}
you'd be able to reconstruct array B if you had array A.
One mistake would be to go and find biggest subset only. Then the solution would have biggest subset, but not minimum amount of subsets possible.
Example:
a = [1,3,4,4,3,0,8,3,5,5,2,8,3,1,0,9];
|^||^||^||^||^|| ^ ||^|
Although this has longest subset, but It ended up with 6 blocks. Whereas,
b = [1,3,4,4,3,0,8,3,5,5,2,8,3,1,0,9];
| ^ || ^ || ^ |
here each subset might not be the longest but there are fewer subsets to cover whole array.
[0,1,2,3,4,5,6,7,8,9, .... ]
$\endgroup$