Physical Examination
You have two rows of students with n students each.
Let: h1[i] = height of student in row 1 at column i , h2[i] = height of student in row 2 at column i
You choose students from left → right.
Rules: indices must strictly increase and You cannot pick two consecutive students from the same row.
Your task is to maximize the total height of the chosen team.
Example 1:
Input: n = 5 , h1 = [9, 3, 5, 7, 3] , h2 = [5, 8, 1, 4, 5]
Output: 29
Explanation:
One optimal sequence:
h1[1] = 9 h2[2] = 8 h1[3] = 5 h2[4] = 4 h1[5] = 3
Total: 9 + 8 + 5 + 4 + 3 = 29
We alternate rows while moving right.
Example 2:
Input: n = 3, h1 = [1, 2, 9], h2 = [10, 1, 1]
Output: 19
Explanation:
Best choice:
h2[1] = 10 h1[3] = 9
Total: 10 + 9 = 19
Now Your Turn!
Pick the correct output for the given inputInput : n = 5 , h1 = [1,100,1,100,1] , h2 = [100,1,100,1,100]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
1 ≤ n ≤ 105
1 ≤ h1i ≤ 109
1 ≤ h2i ≤ 109