The runtime, once again, makes no sense. Think of these situations:
a.len = b.len; a * (b - a + 1) = a
b.len = 1; a * (1 - a + 1) => do fuzzy math by dropping the constants => a * a.
The above is saying this:
a = [1]
b = [1, 2, 3, 4, 5, 6, 7, 8]
is slower than this:
a = [1, 2, 3, 4, 5, 6]
b = [1, 2, 3, 4, 5, 6, 7, 8]
I think this may be a variation on the Longest Common Sequence Problem:
https://en.wikipedia.org/wiki/Longes...quence_problem
I never heard of LCS before, but I guess it is a major thing.
Another part of me thinks there is a bit of knapsack going on here as well. That can be optimized using bisection search.