##### Short Problem Definition:

There are n piles of stones, where the ith pile has ai stones. You need to collect the maximum number of stones from these piles

##### Link

##### Complexity:

time complexity is O(N)

space complexity is O(1)

##### Execution:

This challenge is fairly simple. It does not matter how those stones are arranged. The only important bit is that either the sum of all even elements is bigger than the sum of all odd elements or vice versa.

##### Solution:

def maximumStones(arr): return 2*min(sum(arr[0::2]), sum(arr[1::2]))

If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.