Company: Uber

Difficulty: medium

Problem Statement

Maximum Sum with Limited Consecutive Picks Two arrays B and C both have length N . At every index, choose exactly one of B[i] or C[i] . You may not choose from the same array at three consecutive indices. Find the maximum possible sum. Input The first line contains N . Each of the next N lines contains B[i] C[i] . Output Print the maximum sum. Constraints 1 <= N <= 100000 1 <= B[i], C[i] <= 10000000000 Use a 64-bit integer. Example Input: 3 5 10 3 10 4 10 Output: 25 Notes Runs of length one or two from an array are allowed; a run of length three is not.

More Uber OA questionsInterview experiences