HackerRank 'Game of Maximization' Solution

Martin Kysel · January 24, 2021

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

Stones Problem

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]))

Twitter, Facebook

To learn more about solving Coding Challenges in Python, I recommend these courses: Educative.io Python Algorithms, Educative.io Python Coding Interview.