Sum String Check
Updated
Problem statement
A sum string is a string of digits that can be cut into a sequence of at least three numbers, where every number after the first two equals the sum of the two numbers just before it. The cut keeps the digits in order and must use every digit.
No number in the sequence may have a leading zero. The number 0 itself is allowed, but pieces such as 05 or 00 are not.
Given a digit string s, return true if it is a sum string and false otherwise.
The numbers can have many digits, far more than fit in a 64-bit integer.
Function
isSumString(s: String) → booleanExamples
Example 1
s = "4610162642"return = trueSplit the string as 4, 6, 10, 16, 26, 42. Each number after the first two is the sum of the two before it: 4 + 6 = 10, 6 + 10 = 16, 10 + 16 = 26 and 16 + 26 = 42.
Example 2
s = "1011"return = trueSplit it as 1, 0, 1, 1. Then 1 + 0 = 1 and 0 + 1 = 1. A number may be a single 0.
Example 3
s = "1203"return = falseThe sums would work for 1, 2, 03, but 03 has a leading zero, so that split is not allowed. No other split works: for example, 1 + 20 = 21, not 3, and 12 + 0 = 12, not 3.
Constraints
4 <= s.length <= 100scontains only the digits0to9.
More Nutanix Online Assessment questions
- Good SubsequencesOA · Seen Jul 2026
- Min Cost to Connect All PointsOA · Seen Jun 2026
- Digit Changes for a Multiple of 9OA · Seen Aug 2025
- Gas Station Loop StartOA · Seen Aug 2025
- Number of Players (for MTS2)OA · Seen Oct 2024
- Work Schedules (for MTS2)OA · Seen Oct 2024
- Minimum Operations to Convert ArrayOA · Seen Apr 2024
- No Adjacent CharactersOA · Seen Apr 2024
- Build a BST From a ListOA · Seen Nov 2022
- Delete Even-Valued Nodes From a Linked ListOA · Seen Nov 2022
Similar questions at other companies
- Perfect Squares Matching a PatternNielsen · OA
- Simplify a Quadratic ExpressionOpenAI · OAOpenAI interview questions
- Next Number with Disjoint DigitsElevenLabs · OAElevenLabs interview questions
- Vowel Substring GameAkuna Capital · OAAkuna Capital interview questions
- Minimum Anagram PeriodVisa · OAVisa interview questions
- Return Exact Cash Register ChangeBank of America · OA
- Maximum Equal Parts for PrefixesAmazon · OA
- Minimum Anagram PeriodWells Fargo · OAWells Fargo interview questions
- Minimum Digit Swaps for the Smallest DifferenceLSEG · OALSEG interview questions
- Vowel Substring Deletion GameJP Morgan Chase · OAJP Morgan Chase interview questions