You are viewing a single comment's thread. Return to all comments →
I'm assuming that you meant :
1 5 100 2 100 2 100
Output for the above should be : 396
Why not 392 ?
Because the result S is calculated using A (not B).
For the given B = 100, 2, 100, 2, 100, maximum value occurs for A = 100, 1, 100, 1, 100.
B = 100, 2, 100, 2, 100
A = 100, 1, 100, 1, 100
alternative postitions in array should be 1 then the sum will be maximum
eg: 100 1 100 1 100
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Sherlock and Cost
You are viewing a single comment's thread. Return to all comments →
I'm assuming that you meant :
Output for the above should be : 396
Why not 392 ?
Because the result S is calculated using A (not B).
For the given
B = 100, 2, 100, 2, 100
, maximum value occurs forA = 100, 1, 100, 1, 100
.alternative postitions in array should be 1 then the sum will be maximum
eg: 100 1 100 1 100