Skip to content

Commit

Permalink
Merge pull request #23 from ayush987goyal/16-solution
Browse files Browse the repository at this point in the history
#16 Power Hungry Solution
  • Loading branch information
the-vampiire authored Oct 5, 2018
2 parents f7b44a9 + d3174db commit 4ef0c4f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions wizard_apprentice/power-hungry_ayush987goyal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def answer(panels):
max_power = 1

panels.sort()
index = 0

while index < len(panels):
if panels[index] > 0:
max_power = max_power * panels[index]
index += 1
elif panels[index] < 0:
if (index + 1 < len(panels)) and panels[index + 1] < 0:
max_power = max_power * panels[index] * panels[index + 1]
index += 2
else:
index += 1
else:
index += 1

return max_power


tests = [[-2, -3, 4, -5], [2, 0, 2, 2, 0], [-3, -4, -5, -6, -7]]

for test in tests:
print(answer(test))

0 comments on commit 4ef0c4f

Please sign in to comment.