Mario drives on a two-lane freeway with coins every mile. You are given two integer arrays,
lane1andlane2, where the value at theithindex represents the number of coins he gains or loses in theithmile in that lane.
- If Mario is in lane 1 at mile
iandlane1[i] > 0, Mario gainslane1[i]coins.- If Mario is in lane 1 at mile
iandlane1[i] < 0, Mario pays a toll and losesabs(lane1[i])coins.- The same rules apply for
lane2.Mario can enter the freeway anywhere and exit anytime after traveling at least one mile. Mario always enters the freeway on lane 1 but can switch lanes at most 2 times.
A lane switch is when Mario goes from lane 1 to lane 2 or vice versa.
Return the maximum number of coins Mario can earn after performing at most 2 lane switches.
Note: Mario can switch lanes immediately upon entering or just before exiting the freeway.
1 | class Solution { |