FastPrepCount Equal-Distinct Character Partitions

Count Equal-Distinct Character Partitions

Infosys logoInfosys● HardNEW GRADOA
Learn

Problem statement

Partition a non-empty lowercase string into one or more non-empty contiguous parts. A partition is valid when every part contains the same number of distinct characters.

Return the number of valid partitions modulo 1,000,000,007.

Function

countEqualDistinctPartitions(value: String) → int

Examples

Example 1

value = "aaa"return = 4

Every cut pattern is valid because every non-empty part has one distinct character.

Example 2

value = "abca"return = 3

The valid partitions are the whole string, four single characters, and ab | ca.

Constraints

  • 1 <= value.length <= 100000
  • value contains only lowercase English letters.

Source note: Interview prompt excerpt preserved as source evidence.

More Infosys problems

See Infosys hiring insights
public int countEqualDistinctPartitions(String value) {
    // Write your code here.
}
value"aaa"
expected4
Checking account…