A factory conveyor line carries a single-file sequence of parts, and each part is stamped with an integer tag as it passes the scanner. Quality control has flagged one tag value for an immediate recall: every part stamped with that tag must be pulled off the line, while every other part keeps moving, and the parts that remain must end up pressed back together, in their original relative order, with no gaps left behind. Given the tag sequence read off the line and the recalled tag value, report the sequence of tags that remains on the line after the sweep.
n (0 <= n <= 200000) — the number of parts currently on the line.n space-separated integers, the tag stamped on each part in line order (this line may be blank when n == 0).target (-10^9 <= target <= 10^9) — the recalled tag value.Print the tags remaining on the line, in their original order, separated by single spaces, on one line. If no parts remain, print an empty line.
target satisfies -10^9 <= value <= 10^9.target must all be kept.Example 1
Input
6 7 1 7 3 7 5 7
Expected
1 3 5
Explanation
The recalled tag is 7, so the parts stamped 7 (positions 1, 3, and 5 on the line) are pulled off. The remaining tags 1, 3, and 5 stay in their original order, giving "1 3 5".
Example 2
Input
4 2 4 6 8 5
Expected
2 4 6 8
Explanation
None of the four parts carry the recalled tag 5, so the line is unchanged and all four tags remain in order: "2 4 6 8".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →