Equal-Sum Digit Partitions
Updated
Problem statement
You are given a nonempty string digits made of decimal digits. You may insert zero or more underscores between neighboring digits. The underscores split the string into segments, and the result is called a partition.
A partition is valid when every segment has the same digit sum. The digit sum of a segment is the total of its digits. Return all valid partition strings in standard lexicographic order.
The uncut input always counts as a valid partition with one segment. Do not drop leading zeroes. They stay part of their 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.
More Alchemy interview questions
Similar questions at other companies
- Next Number with Disjoint DigitsElevenLabs · OAElevenLabs interview questions
- String Permutations in Custom Character OrderWex · OA · PHONE SCREEN
- Generate ParenthesesThe Walt Disney Company · OAThe Walt Disney Company interview questions
- Reverse and AppendUber · OAUber interview questions
- All Palindrome PartitionsExpedia · OAExpedia interview questions
- Generate ParenthesesAtlassian · OAAtlassian interview questions
- Maximum Number after K SwapsIntuit · OAIntuit interview questions
- Generate Balanced ParenthesesInMobi · OAInMobi interview questions
- Work ScheduleSnowflake · OASnowflake interview questions
- Work Schedules (for MTS2)Nutanix · OANutanix interview questions