FastPrepEqual-Sum Digit Partitions
Problems/Equal-Sum Digit Partitions

Equal-Sum Digit Partitions

Alchemy logoAlchemy● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A first-hand report from an Alchemy online assessment gives this digit-partition task. Its first example has one typo in a cut position. It also sorts by the number of segments even though it says lexicographic. Our version follows the written lexicographic rule and fixes the arithmetic. It is about 85% the same as the reported question.

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.
  • digits contains only characters 0 through 9.

More Alchemy interview questions

  • Count Class-C IPv4 AddressesPHONE SCREEN · Seen Jul 2024

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
See Alchemy hiring insights
Saved
class Solution {
    public String[] equalSumPartitions(String digits) {
      // write your code here
    }
}
Checking account…