Given an array of coins each having some value.Array size is N. You can change the value of any any coin except the first and last coin. You can change the value of ith coin to half of sum of value of (i-1)th and (i+1)th coin but for doing so, two condition needs to be satisfied.
(1) value of both (i-1)th and (i+1)th coin should be even and
(2) if jth coin’s value is changed after ith coin’s value then j should be greater than i
Now your task is to maximize the absolute difference between the sum of values of 1st half of coins of array and values of 2nd half of the coins of array. If array size is odd ignore middle element.
Can anyone suggest me the algo to find the answer.
The task is to find the maximum absolute diffeerence.
My algo: 1. find sums of left half and right half 2. if left half> right half maximize left half by making operations given and minize left half but i am not geting correct answer.
PS: I attended one interview one week before. It was asked there I could not figure out the approach.