Hiring process8 levels
  1. 1 IQ Test
  2. 2 Additional Online Test (If Required)
  3. 3 Office Interview with Hiring Manager
  4. 4 Unpaid Test Task (Motivation Check)
  5. 5 Paid Test Task and Follow-Up Interview
  6. 6 Iterative Paid Test Tasks
  7. 7 Office Verification
  8. 8 Final Interview with the Founder

Problems > K-th of Two Sorted Arrays

K-th of Two Sorted Arrays

Difficulty: 1400 3000 ms 128 MB

two-pointers

Two arrays are already sorted. Print the K-th smallest element of their union (duplicates kept).

Input: the first line has N, M and K; the second line has the N sorted values of A; the third line has the M sorted values of B.

Output: the K-th smallest element of the merged multiset.

Constraints:

  • 1 ≤ N, M ≤ 105
  • 1 ≤ K ≤ N+M
  • −109 ≤ values ≤ 109

Sample Tests

Input 1
3 3 4
1 3 5
2 4 6
Output 1
4
Input 2
1 1 2
5
1
Output 2
5

Read the Editorial Statistics

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.
Ctrl+Enter submit · Ctrl+Space autocomplete · F11 fullscreen