Problem
Count Prime Strings
Learn this problemProblem statement
Given a string s representing a non-negative decimal integer, count the number of ways to split it into one or more prime numbers.
A valid split must follow all of these rules:
- The digits remain in their original order, and every digit is used exactly once.
- Each piece is interpreted as a decimal integer between
2and10^6, inclusive. - No piece may contain a leading zero.
Return the number of valid splits modulo 10^9 + 7.
Function
countPrimeStrings(s: String) → intExamples
Example 1
s = "11375"return = 3The string can be split into primes in three ways: [11, 37, 5], [11, 3, 7, 5], and [113, 7, 5].
Constraints
1 <= s.length <= 10^5scontains only decimal digits.s[0] != '0'
More Salesforce problems
- Diameter of an Acyclic Undirected GraphONSITE INTERVIEW · Seen Jul 2026
- Optimal Account BalancingPHONE SCREEN · Seen Jul 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Jul 2026
- Maximal SquarePHONE SCREEN · Seen Jul 2026
- Maximum Barbell WeightOA · Seen Jul 2026
- Minimum No-Repeat Segments After One Character RemovalOA · Seen Jul 2026
- Minimum Operations to ZeroOA · Seen Jul 2026
- Minimize Total Input Cost (for LTMS)OA · Seen Jun 2026