FastPrepCount Prime Strings
Problems/Count Prime Strings

Count Prime Strings

Salesforce logoSalesforceFULLTIMEONSITE INTERVIEW

Updated Jul 2026

QuestionFunctionExamplesConstraints

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 Onsite Interview questions

  • Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
  • Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
  • 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
  • Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
  • Group Identical Tree LevelsONSITE INTERVIEW · Seen Oct 2026
  • Meeting Rooms IIONSITE INTERVIEW · Seen Oct 2026
  • Construct a Tree from Level-Order and Inorder TraversalsONSITE INTERVIEW · Seen Sep 2026
  • Maximize Monsters DefeatedONSITE INTERVIEW · Seen Sep 2026

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public int countPrimeStrings(String s) {
      // write your code here
    }
}
Checking account…