#200. 有序数组交集计数
有序数组交集计数
Count of Intersection in Sorted Arrays
Background
In data processing and algorithmic competitions, it is often necessary to efficiently process and analyze sorted data. This problem aims to test your ability to efficiently traverse sorted arrays and find common elements.
Problem Description
Given two arrays of strings, and , each in alphabetical order, possibly with duplicates. Return the count of the number of strings which appear in both arrays. The optimal "linear" solution makes a single pass over both arrays, taking advantage of the fact that they are in alphabetical order.
Input Format
The input consists of a single line.
This line contains the representation of two string arrays. The elements of the first array are enclosed in double quotes and separated by spaces, followed by ] [ (or ] and [), and then the elements of the second array, also enclosed in double quotes and separated by spaces.
For example: "str1" "str2"] ["str3" "str4".
Output Format
An integer representing the count of strings that appear in both arrays.
Sample
"a" "c" "x"] ["b" "c" "d" "x"
2
"a" "c" "x"] ["a" "b" "c" "x" "z"
3
"a" "b" "c"] ["a" "b" "c"
3
Sample Explanation
For Sample 1: Array is `["a\