Loading...
Loading...
Loading...
A shop has a catalogue of products. Orders then arrive one product at a time, and some products in the orders are not in the catalogue. Find the position of the order at which every catalogue product has been ordered at least once.
NOT YET if some catalogue product is never ordered.Example
Input
3 laptop mouse cable 6 mouse tablet laptop mouse cable laptop
Output
5
cable, the last missing product, arrives at position 5. tablet is not in the catalogue and is ignored.
Try the problem first. Open one hint at a time.
Put the catalogue products in a HashSet of products still waiting to be ordered.
remove returns true only when the product was in the set. When the set becomes empty, the current position is the answer.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor