Problem

Count Prime Strings

Learn this problem
Salesforce logoSalesforceFULLTIMEONSITE INTERVIEW
See Salesforce hiring insights

Problem 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 2 and 10^6, inclusive.
  • No piece may contain a leading zero.

Return the number of valid splits modulo 10^9 + 7.

Function

countPrimeStrings(s: String) → int

Examples

Example 1

s = "11375"return = 3

The 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^5
  • s contains only decimal digits.
  • s[0] != '0'

More Salesforce problems

drafts saved locally
public int countPrimeStrings(String s) {
  // write your code here
}
s"11375"
expected3
checking account