0

# You are given an array of size N. You want to maximize the sum of elements on the odd indices of array

I don't understand the question and test cases can someone help Test Cases - 1. N = 10 Array - [8, 1, 2, 1, 1, 8, 6, 3, 6, 1] Ans - 16 Resulting array - [8, 2, 1, 8, 6, 6] Sum of odd indices is going to equal to 16 2. N = 10 Array - [3, 9, 9, 1, 10, 4, 3, 3, 10, 8] Ans - 32 Resulting array - [3, 9, 9, 10, 4, 3, 3, 10] Sum of odd indices is going to equal to 32 3. N = 10 Array - [8, 6, 6, 2, 2, 1, 9, 3, 4, 6] Ans - 23 Resulting array - [8, 6, 6, 2, 2, 9, 3, 6] Sum of odd indices is going to equal to 23

2 Answers

+ 3

Basically the question is trying to say to modify the array by erasing the elements and get a resultant array so that sum of elements at the odd indices become maximum.
For ex. We have
Array - [8, 1, 2, 1, 1, 8, 6, 3, 6, 1]
Sum = 14
If we modify the array by erasing the elements at indices 1, 3, 7, 9
We have now
Resulting array - [8, 2, 1, 8, 6, 6]
Sum = 16 i.e. max

+ 1

You should think about the logic for which elements should be erased so that resultant array have elements at odd indices make the sum maximum.