← 返回 netflix 的题目列表Homepage Deduplication Across Rows and Globally
类型:online_judge
Problem: Homepage Deduplication (Per-Row + Global)
You are implementing a homepage deduplication rule. The homepage consists of multiple horizontal rows (rails) that users can scroll horizontally, and users can also scroll vertically across rows.
Given a 2D list shows where shows[i] is the list of show names (strings) for row i, ignore ranking/recommendation and perform deduplication only.
Dedup Rules
Within-row dedup: a show name must not repeat within the same row (keep the first occurrence, skip later duplicates).
Global dedup: a show name must not appear in multiple rows (keep it in the earliest row where it first appears; skip occurrences in later rows).
Stability: preserve the original relative order within each row.
Input Format
Line 1: integer R, number of rows.
Next R lines: each line is a space-separated list of show names; an empty line represents an empty row.
Output Format
Print R lines representing the deduplicated rows (space-separated).
Constraints
1 <= R <= 2000
0 <= C_i <= 2000 per row
Show names are visible ASCII and contain no spaces
Total items sum(C_i) <= 2e6
Sample Tests
Test 1 Input:
3
A B C A
B D E
E F A
Output:
A B C
D E
F
Test 2 Input:
2
X X X
X Y X Z
Output:
X
Y Z
Test 3 Input:
4
A
A A A
B A C
Output:
A
B C
Test 4 Input:
1
A B C
Output:
A B C
Test 5 Input:
3
A
A
Output:
A
Example
Input
3
A B C A
B D E
E F A
Output
A B C
D E
F