Prime String
Learn this problemProblem statement
Given a string of length n consisting of digits [0-9], count the number of ways the given string can be split into prime numbers. The digits must remain in the order given and the entire string must be used. Each number must be in the range 2 to 106 inclusive, and may not contain leading zeros. Since the answer can be large, return the answer modulo (109 + 7).
Note: The initial string does not contain leading zeros.
Function
countPrimeStrings(s: String) → int
Complete the function countPrimeStrings in the editor below.
countPrimeStrings has the following parameter(s):
- string s: a string of digits
Returns
int: the number of ways the string can be split into primes, modulo 1000000007, (109+7)
Examples
Example 1
s = "11375"return = 3This string can be split into primes 3 different ways: [11, 37, 5], [11, 3, 7, 5], [113, 7, 5].
Constraints
- 1 ≤ length of s ≤ 105
there should be more of them. I will add once find more reliable reference 🐸
More Snowflake problems
- Minimum N-ary Tree Depth DeletionsPHONE SCREEN · Seen Jul 2026
- Simulate a Queued Multi-Rule Rate LimiterPHONE SCREEN · Seen Jul 2026
- Minimum Clicks Between Wiki PagesOA · Seen Jul 2026
- Closest Target CharacterPHONE SCREEN · Seen Jul 2026
- Horizontal Pod AutoscalerOA · Seen Jul 2026
- Minimum HeightOA · Seen Jul 2026
- Vowel SubstringOA · Seen Jun 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Jun 2026