← Back to challenges

Product of Remaining Elements

PythonHardarrayslogicloops

Instructions

Write a function that returns True if you can partition a list into one element and the rest, such that this element is equal to the product of all other elements excluding itself.

Examples

can_partition([2, 8, 4, 1]) ➞ True
# 8 = 2 x 4 x 1

can_partition([-1, -10, 1, -2, 20]) ➞ False

can_partition([-1, -20, 5, -1, -2, 2]) ➞ True

Notes

  • The list may contain duplicates.
  • Multiple solutions can exist, any solution is sufficient to return True.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.