Problem

Count Prime Strings

SalesforceFULLTIMEONSITE INTERVIEW
See Salesforce hiring insights

Given a string s representing an integer, count the number of ways to split the string into one or more prime numbers.

The digits must stay in their original order, and every digit in s must be used exactly once.

Each split segment must be interpreted as a decimal integer and must be prime.

Examples
01 · 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
  • s contains only digits.
  • The answer fits in a 32-bit signed integer.
More Salesforce problems
drafts saved locally
public int countPrimeStrings(String s) {
  // write your code here
}
s"11375"
expected3
sign in to submit