EasyArrays · Math

Plus One

digits holds a large integer, most significant digit first, with no leading zero. Return the digits of that number plus one.

[1,2,3,4] → [1,2,3,5] (1234 + 1 = 1235)[9,9,9] → [1,0,0,0]

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Variables

The data structures the code is building

Digits

9s roll over to 0 and the +1 carry moves left

Time and space complexity

n = number of digits. The highlighted row is the solution being traced.

Keyboard: ← → step, Space play or pause. Enter 1 to 10 digits like [1,2,9].