LC 66 — Problem

You are given a large integer represented as an integer array digits, where each digits[i] is the i-th digit of the integer. The digits are ordered from most significant to least significant. Increment the large integer by one and return the resulting array of digits.

Input: digits = 123
Output: 124
Explanation: The array represents the integer 123. 123 + 1 = 124.
Input: digits = [9]
Output: 10

Constraints: 1 ≤ digits.length ≤ 100 · 0 ≤ digits[i] ≤ 9 · No leading zeros

Given an array of digits representing a large integer, add 1 and return the result as an array. Sounds trivial — just convert to a number, add 1, convert back.

Before we try that, let's see if you can spot the danger. Here's a 20-digit number — nothing but nines.

Input
[9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9]

20 digits — each one is 9.