Archive / 2021 / Selection Test
Maximum Power Battery Array
The asymmetric battery array is a line of batteries placed sequentially. Each battery has a different amount of power.
If Tony chooses to activate the battery n, he can’t draw power from surrounding batteries.
Your task is to help Tony calculate the maximum power he can get out of this asymmetric battery array.
Input Format
- First line will contain
n, number of batteries in Tony’s battery array - Next
nlines will contain the powers of each battery
Output Format
A single integer P, indicating the maximum power that can be generated.
Constraints
1 <= n <= 1000 <= n[i] <= 500
Sample Input 0
4
1
2
3
1
Sample Output 0
4
Sample Input 1
5
2
7
9
3
1
Sample Output 1
12
Open on HackerRank ↗ · Markdown source · Back to the archive