Check if a Number is a Keith Number

Given a positive integer n, return true if n is a Keith number. For a d-digit number, start a sequence with its d decimal digits. Each next term is the sum of…

Given a positive integer `n`, return `true` if `n` is a Keith number. For a `d`-digit number, start a sequence with its `d` decimal digits. Each next term is the sum of the previous `d` terms. A number with at least two digits is Keith if this sequence reaches `n`.

- `1 ≤ n ≤ 10^6` - `n` is always a positive integer.

Example 1: input n = 197; output true. Starting with 1, 9, 7 gives 17, 33, 57, 107, then 197.

Example 2: input n = 20; output false. Starting with 2, 0 gives 2, 2, 4, 6, 10, 16, then 26, which passes 20.

Category: Math. Topic: math. Difficulty: Easy. Patterns: math.