Count Numbers with a Prime Digit Sum
Updated
Problem statement
The strings lower and upper give positive integers L and R in decimal, with no leading zeros. Count the integers x in the inclusive interval [L, R] whose decimal digit sum is prime.
A prime is an integer greater than one with exactly two positive divisors. Return the exact count as a decimal string with no leading zeros, except for "0" when the count is zero.
Function
countPrimeDigitSums(lower: String, upper: String) → StringExamples
Example 1
lower = "1"upper = "20"return = "9"The qualifying numbers are 2, 3, 5, 7, 11, 12, 14, 16, and 20.
Example 2
lower = "98"upper = "102"return = "3"The qualifying numbers are 98, 101, and 102, with digit sums 17, 2, and 3.
Constraints
1 <= L <= R <= 10^18.- Input strings contain only decimal digits and have no leading zeros.
- Use exact integer arithmetic; no modulo is applied.
More Rippling Online Assessment questions
- Most Segments That Sort the ArrayOA · Seen Nov 2026
- Palindromic Paths to the RootOA · Seen Nov 2026
- Server InvestmentOA · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- REST API: Highest International StudentsOA · Seen Sep 2026
- Token ValidationOA · Seen Sep 2026
- Consistent LogsOA · Seen Sep 2026
- Costliest ChocolateOA · Seen Sep 2026
- Server ManagementOA · Seen Sep 2026
- Cyber Beacon DetectionOA · Seen Aug 2026
Similar questions at other companies
- At Most K Jumps with Quadratic Transition CostInfosys · OAInfosys interview questions
- Maximum Signal Walk in a Server TreeTower Research Capital · OA
- Count Nondecreasing Digit-Sum ArraysMicrosoft · OAMicrosoft interview questions
- Jump Game with Prime-3 StepsUber · OAUber interview questions
- Profitable Currency Exchange CycleOptiver · OAOptiver interview questions
- Match an XOR-Adjusted SumSquarepoint Capital · OASquarepoint Capital interview questions
- Count Permutations Without Three Equal Parities in a RowGoogle · OAGoogle interview questions
- TikTok UserTikTok · OATikTok interview questions
- String Transformation (Also for Infra Automation Intern)Snowflake · OASnowflake interview questions
- Digit SumBank of New York Mellon · OA