Get the Maximum Score
Explore how to apply the two-pointer technique to find the maximum possible score by traversing two sorted arrays with distinct integers. Understand when to switch between arrays at common elements to optimize the path and return the result modulo 10^9+7.
We'll cover the following...
Statement
You are given two sorted arrays of distinct integers, nums1 and nums2.
A valid path is constructed according to the following rules:
You start at the index
of either nums1ornums2.From there, you must traverse the chosen array from left to right.
Suppose you encounter a number in both arrays (a common element, not necessarily at the same index). In that case, you may choose to switch to the other array at that element and continue the traversal from that point forward.
A common element can only be counted once in the total path score, regardless of the array it appears.
The score of a path is defined as the sum of all unique elements visited during traversal. Your task is to ...