Maximum Sum with Equal-Index Switches
Updated
Problem statement
Two arrays a and b have equal length. Start in either array at index zero and visit every index from left to right, collecting the value at that index in the current array. At index i, you may switch arrays only if a[i] == b[i]. The common value is collected once. Return the maximum total after reaching the end.
The arrays need not be sorted. Equal values at different indices do not allow a switch. You must traverse the full length even when some values are negative. Empty arrays have total zero.
Function
maximumSwitchingSum(a: int[], b: int[]) → longExamples
Example 1
a = [1,2,4,7,9,12,3,6]b = [1,5,7,8,9,3,5,7]return = 51Choose b through the shared 9, then a through the end: 1+5+7+8+9+12+3+6=51.
Example 2
a = [1,10]b = [10,1]return = 11No same-index equality exists, so a cross-index common value does not permit switching.
Constraints
- For this exercise, assume equal lengths at most 200000 and values between -10^9 and 10^9. Return a signed 64-bit sum.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- 0/1 KnapsackConfluent · OAConfluent interview questions
- Minimum Cost to Tile a Strip with Widths 1, 2, and 3Infosys · OAInfosys interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Maximum Subarray SumStraive · OA
- Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
- Lowest-Cost Shirt Color ScheduleElevenLabs · OAElevenLabs interview questions
- Maximum Game Board ScoreJP Morgan Chase · OAJP Morgan Chase interview questions
- API Bandwidth AllocationArista Networks · OAArista Networks interview questions
- Maximum Points by Deleting ElementsIBM · OAIBM interview questions