Skip to content

Practice Number of Beautiful Partitions

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2478
LeetCode Problem

Number of Beautiful Partitions

Problem Statement

Partition all of s into exactly k nonempty contiguous pieces. Every piece must have length at least minLength, start with one of the prime digits 2, 3, 5 or 7, and end with a non-prime digit. Return the number of valid partitions modulo 10^9 + 7.

Source: Number of Beautiful Partitions on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "23542185131", k = 3, minLength = 2
Output
3

# Example 2

Input
s = "23542185131", k = 3, minLength = 3
Output
1

# Example 3

Input
s = "3312958", k = 3, minLength = 1
Output
1

Constraints

1 <= k, minLength <= s.length <= 1000
s consists of the digits '1' to '9'.

Related LeetCode Problems

Practice more problems similar to Number of Beautiful Partitions.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.