Skip to content

Commit

Permalink
the-vampiire#16 Power Hungry Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush987goyal authored and Ayush Goyal committed Oct 5, 2018
1 parent 29db125 commit d3174db
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 d3174db

Please sign in to comment.