3 ms·
My quick take on it is that you have to generate a list of all the 1-tuples, 2-tuples and 3-tuples in that very long string, along with the start and end indexe
by msandford 13y ago
My quick take on it is that you have to generate a list of all the 1-tuples, 2-tuples and 3-tuples in that very long string, along with the start and end indexes of each tuple.
Then you find a set of tuples which cover 1-250 (missing one number) and which don't overlap.
You can start by filtering out all the 3-tuples which are over 250.
I might use a hash table to put together a list of all duplicates. Any hash table entry with no duplicates has to be right. Use the indexes that have been removed from the "eligible" pool to remove tuples from the hash table. Iterate.
Of course it's entirely possible that iterating like that could still leave you without a solution. At which point a guess has to be made and to continue solving. If said guess is bad, backtrack and make a different guess.
Obviously it's harder to implement than to outline. And I've probably missed a bunch of optimization.