All problems
Additive Number Check
Problem
Return True if the digit string can be split into an additive sequence of at least three numbers where every number from the third onward is the sum of the previous two.
Try every possible first and second number, reject numbers with leading zeros unless they are the single digit 0, and grow the sequence until it matches the whole string. Numbers may be very large.
Hint
A leading zero in a multi-digit number immediately disqualifies that split.
Test cases
case 1
in: ["112358"]
expected: true
case 2
in: ["199100199"]
expected: true
case 3
in: ["123"]
expected: true
case 4
in: ["1023"]
expected: false
case 5
in: ["1203"]
expected: false
Starter codePython
def additive_number(num):
# Your code here
pass5 test cases · run your code against them in the editor