Given a sequence such as S = {1,8,2,1,4,1,2,9,1,8,4}, I need to find the minimal-length subsequence that contains all element of S (no duplicates, order does n
I'd say:
Obviously, only item 3. is tricky. I'd use a priority queue / heap that assigns a key to each element from D and has the element as value. Apart from that you'll want a data structure that is able to access the elements in the heap by their value (map w/ pointers to the elements). The key should always be the last position in S that the element has occurred.
So you go through S and for each char you read, you do one of setKey O(log n) and then look at the current min O(1) and write it to in the array.
Should be O(n * log n). I hope I didn't miss anything. It just came to my mind, so take it with a grain of salt, or let the community point out possible mistakes I might have made.