Katkat

Implement Plus One

CoinbaseData Scientist · Onsite

Last updated

This question evaluates array manipulation and numeric carry propagation skills, along with the ability to reason about time and space complexity when performing arithmetic on digit lists.

Given a non-empty array of digits representing a non-negative integer, where the most significant digit comes first and each element is in [0, 9], add one to the integer and return the resulting array of digits.

You may not convert the entire array directly into a built-in big integer.

Examples:

  • [1, 2, 3] -> [1, 2, 4]
  • [4, 3, 2, 1] -> [4, 3, 2, 2]
  • [9, 9, 9] -> [1, 0, 0, 0]

Discuss the time and space complexity of your approach.