Loading...
Loading...
Loading...
A cart page lists product ids in the order the customer added them, with repeats. Show each id once, in the order it first appeared.
Example
Input
6 P3 P1 P3 P2 P1 P3
Output
P3 P1 P2
P3 P1 P2: each id at its first position.
Try the problem first. Open one hint at a time.
A LinkedHashSet removes repeats and remembers the order of adding.
Join the values with a space, no space at the end.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor