Given 2 sorted arrays (in increasing order), find a path through the intersections that produces maximum sum and return the maximum sum.
Answers
Answered by
0
Answer:
Step-by-step explanation:
Input: ar1[] = {2, 3, 7, 10, 12}, ar2[] = {1, 5, 7, 8}
Output: 35
35 is sum of 1 + 5 + 7 + 10 + 12.
We start from first element of arr2 which is 1, then we
move to 5, then 7. From 7, we switch to ar1 (7 is common)
and traverse 10 and 12.
Input: ar1[] = {10, 12}, ar2 = {5, 7, 9}
Output: 22
22 is sum of 10 and 12.
Since there is no common element, we need to take all
elements from the array with more sum.
Input: ar1[] = {2, 3, 7, 10, 12, 15, 30, 34}
ar2[] = {1, 5, 7, 8, 10, 15, 16, 19}
Output: 122
122 is sum of 1, 5, 7, 8, 10, 12, 15, 30, 34
Hope it helps you...
Similar questions