Best Score Switching Between Two Sorted Arrays
Updated
Problem statement
You are given two strictly increasing integer arrays nums1 and nums2. A path starts at the first element of either array and walks through that array from left to right. Whenever the current value also appears in the other array, the path may move to that value in the other array and keep walking right from there. The path ends after the last element of the array it is in.
The score of a path is the sum of the values it walks through; a value found in both arrays is counted once, whether or not the path switches there. Return the largest possible score. It can be larger than a 32-bit integer can hold, so return it as a 64-bit integer.
Function
maxSwitchingScore(nums1: int[], nums2: int[]) → longExamples
Example 1
nums1 = [3,6,10,14,20]nums2 = [1,6,8,9,14,15]return = 60Before 6, the first list gives 3 and the second gives 1, so start on the first. Between 6 and 14, the first list has 10 and the second has 8 + 9 = 17, so switch at 6. After 14, 20 beats 15, so switch back at 14. The score is 3 + 6 + 17 + 14 + 20 = 60.
Example 2
nums1 = [5,11]nums2 = [2,4,7]return = 16No value is in both lists, so no switch is possible. The first list sums to 16 and the second to 13, so the answer is 16.
Example 3
nums1 = [4,9,12]nums2 = [4,9,12]return = 25Both lists are the same, so every path collects 4, 9 and 12 once each: 25.
Constraints
1 <= nums1.length, nums2.length <= 50001 <= nums1[i], nums2[i] <= 10^7nums1andnums2are both strictly increasing.
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Split Array to Minimize the Largest SumNation with NaMo · PHONE SCREEN
- Trapping Rain WaterOracle · PHONE SCREENOracle interview questions
- Rain Kept Between WallsDocuSign · PHONE SCREENDocuSign interview questions
- Jump GamePaytm · PHONE SCREENPaytm interview questions
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
- Container With Most WaterEPAM · PHONE SCREENEPAM interview questions
- Container With Most WaterNuro · PHONE SCREENNuro interview questions
- Jump Game IINavi · PHONE SCREEN
- Best Stock Profit With a Sell FeeKaseya · PHONE SCREEN
- Rebalance Bank Accounts to a Minimum BalanceRemitly · PHONE SCREENRemitly interview questions