Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#16 Power Hungry Solution #23

Merged
merged 1 commit into from
Oct 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))