Sherlock and Cost Discussions | Algorithms | HackerRank
  • + 1 comment

    I'm assuming that you meant :

    1
    5
    100 2 100 2 100
    

    Output for the above should be : 396

    • + 2 comments

      Why not 392 ?

      • + 0 comments

        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.

      • + 0 comments

        alternative postitions in array should be 1 then the sum will be maximum

        eg: 100 1 100 1 100