Created
June 24, 2019 11:03
-
-
Save mraarif/7d8c3951aea3067c66416082855e1370 to your computer and use it in GitHub Desktop.
This gist solves the problem of determining whether if given array can be divided into three non empty partitions and sum of those partitions is same.
This file contains hidden or 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
def check_if_passes(input_array): | |
is_divisible = sum(input_array) % 3 == 0 | |
if not is_divisible: | |
return is_divisible | |
chunk = sum(input_array) / 3 | |
entries = [] | |
addition = 0 | |
for item in input_array: | |
addition = item + addition | |
if addition == chunk: | |
entries.append(addition) | |
addition = 0 | |
return len(entries) == 3 | |
my_array = [3, 3, 6, 5, -2, 2, 5, 1, -9, 4] | |
print("\nThe result is: {0}".format(check_if_passes(my_array))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
leetcode source: https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum/