#199. 合并有序字符串数组前N项
合并有序字符串数组前N项
Merge Sorted Array Prefix N
Background
In competitive programming, efficiently combining sorted lists is a common task. This problem asks you to merge two such lists and extract a specific prefix.
Problem Description
Given two arrays of strings, and , each with its elements in alphabetical order and without duplicates. Return a new array containing the first elements obtained by merging the two arrays. The result array should also be in alphabetical order and without duplicates. Both and will have a length of or more.
The best "linear" solution makes a single pass over and , taking advantage of their alphabetical order, copying elements directly to the new array.
Note: For this problem, is fixed at .
Input Format
The input consists of a single line containing two string arrays, and . Elements within each array are space-separated and enclosed in square brackets []. For example: ["a" "c" "z"] ["b" "f" "z"]. Please note that the actual input might exactly match the format shown in the examples, including potential missing brackets.
Output Format
The output should be a single line representing the new string array containing the first merged elements. Elements in the array are comma-separated, quoted, and enclosed in square brackets []. For example: `["a\