Equal-Sum Digit Partitions
Problem statement
Given a nonempty string digits containing decimal digits, insert zero or more underscores between adjacent digits. Keep a partition exactly when every contiguous segment has the same digit sum. Return all valid partition strings in standard lexicographic order.
The uncut input is always a valid one-segment partition. Leading zeroes remain part of their original segments.
Function
equalSumPartitions(digits: String) → String[]Examples
Example 1
digits = "1741380"return = ["1741380","174_1380","17_413_80"]The three valid cuts have common segment sums 24, 12, and 8 respectively.
Example 2
digits = "1111"return = ["1111","11_11","1_1_1_1"]Constraints
1 <= digits.length <= 16.digitscontains only characters0through9.