rod. Choose three cut positions i < j < k; the elements at those positions are thrown away, and the array falls apart into four pieces:
- rod[0..i-1],
- rod[i+1..j-1],
- rod[j+1..k-1],
- rod[k+1..n-1].
Every piece must be non-empty, so 0 < i, i + 1 < j, j + 1 < k and k < n - 1, where n = len(rod).
Return True if the cuts can be chosen so that all four pieces have the same sum, and False otherwise.rod=[2, 5, 1, 1, 7, 2, 0, 9, 2] → True
Cut at positions 1, 4 and 7 (dropping 5, 7 and 9). The pieces left are [2], [1, 1], [2, 0] and [2], each summing to 2.
rod=[3, 1, 3, 1, 3, 1] → False
Four non-empty pieces plus three cuts need at least 7 numbers, and there are only 6.
rod=[1, 8, 3, -2, 0, 1, 5, -1, 2] → True
Cuts at positions 1, 4 and 6 leave [1], [3, -2], [1] and [-1, 2], each summing to 1. Numbers may be negative.
rod=[2, 5, 1, 1, 7, 2, 0, 9, 2]
True
Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.