← 返回 sofi 的题目列表K-th Unique Maximum from Two Sorted Arrays
类型:online_judge
Problem: K-th Unique Maximum from Two Sorted Arrays
Given two ascending sorted integer arrays A and B (each may contain duplicates) and an integer K, return the K-th element in the sequence of distinct (unique) values obtained from A ∪ B, ordered from largest to smallest.
“Unique” means the same value is counted only once even if it appears multiple times in one array or in both arrays.
If the number of distinct values is less than K, return None (or output null).
Input format (recommended)
Line 1: array A (space-separated)
Line 2: array B (space-separated)
Line 3: integer K
Output format
Print the K-th unique maximum; if it doesn’t exist, print None.
Constraints
1 <= len(A), len(B) <= 2 * 10^5
-10^9 <= A[i], B[i] <= 10^9
1 <= K <= len(A) + len(B)
A and B are non-decreasing (ascending)
Example
A = [1, 2, 4, 4, 5]
B = [2, 4, 6]
Distinct values in descending order: [6, 5, 4, 2, 1]
K = 1 => 6
K = 2 => 5
K = 3 => 4
K = 4 => 2
K = 5 => 1
Example
Input
1 2 4 4 5
2 4 6
1
Output
6