# split array with equal sums

🏠
 1 from itertools import accumulate
2 from collections import defaultdict as dd
3
4
5 class Solution:
6     def splitArray(self, A):
7         acc, n, acc_inv = [*accumulate(A)], len(A), dd(list)
8         for i, u in enumerate(acc):
9             acc_inv[u].append(i)
10
11         place = lambda i, j, k: 0 < i and i + 1 < j and j + 1 < k < len(A) - 1
12
13         for j in range(3, n - 1):
14             for k in range(j + 2, n - 1):
15                 accmk = acc[k]
16                 accmax = acc[-1]
17                 kacc = accmax - accmk
18                 for ai in acc_inv[kacc]:
19                     i = ai + 1
20                     print(f'i: {i}, j: {j}, k: {k}: {place(i, j, k)}, ')
21                     if not place(i, j, k):
22                         break
23                     s0 = acc[i-1]
24                     s1 = acc[j-1] - acc[i]
25                     s2 = acc[k-1] - acc[j]
26                     s3 = acc[n-1] - acc[k]
27                     if s0 == s1 == s2 == s3:
28                         print(i, j, k)
29                         return True
30         return False