Last active
October 17, 2020 16:45
-
-
Save hritik5102/37ab207d3a4af787b25433be227887cb to your computer and use it in GitHub Desktop.
Game of Maximization Hackerrank problem solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Author : Hritik Jaiswal | |
Problem : https://www.hackerrank.com/contests/hackerrank-hackfest-2020/challenges/stones-piles | |
Date : October 17 2020 | |
Reference : https://www.youtube.com/watch?v=WxshQC9VDag | |
Challenge : Hackerrank HackFest 2020 | |
''' | |
def maximumStones(arr): | |
# Write your code here | |
oddStone = [] | |
evenStone = [] | |
for index,val in enumerate(arr): | |
if index%2==0: | |
oddStone.append(val) | |
else: | |
evenStone.append(val) | |
if sum(oddStone)==sum(evenStone): | |
return sum(oddStone) + sum(evenStone) | |
elif sum(oddStone)<sum(evenStone): | |
return 2*sum(oddStone) | |
else: | |
return 2*sum(evenStone) | |
if __name__ == '__main__': | |
n = int(input().strip()) | |
arr = list(map(int, input().rstrip().split())) | |
result = maximumStones(arr) | |
print(result) | |
''' | |
Sample Input 0 | |
4 | |
5 1 1 4 | |
Sample Output 0 | |
10 | |
Sample Input 1 | |
3 | |
2 1 2 | |
Sample Output 1 | |
2 | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment