#K47517. Merge Playlists
Merge Playlists
Merge Playlists
You are given two playlists containing song IDs. Your task is to merge these two playlists into one without duplicates, while preserving the original order of appearance. In other words, the songs in the final merged playlist should appear in the same order as they first appear in the input playlists. If a song appears in both playlists, the occurrence from the first playlist is used.
The problem can be summarized as follows:
Given two sequences of integers \(P_1\) and \(P_2\), produce a sequence \(P\) such that: \[ P = \text{merge}(P_1, P_2) \quad \text{where each element in } P \text{ is unique and ordered by first appearance.} \]
Example:
Input: 4 3 1 2 3 4 3 5 6</p>Output: 1 2 3 4 5 6
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains two integers \(n\) and \(m\) separated by a space, where \(n\) is the length of the first playlist and \(m\) is the length of the second playlist.
- The second line contains \(n\) integers representing the first playlist.
- The third line contains \(m\) integers representing the second playlist.
outputFormat
Output the merged playlist as a sequence of integers on one line, separated by spaces. The output should be written to standard output (stdout).
## sample4 3
1 2 3 4
3 5 6
1 2 3 4 5 6