Count Prime Strings
Updated
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
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 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