Math and Geometry
156 / 170Math and GeometryLesson 1 of 5About 61 min
Carrying, borrowing, and the boundary case that appears in every single one of these problems.
This adds one to a digit array but returns the array without handling a carry past the front. Type the three values it prints.
def add_one_broken(digits): result = digits[:] index = len(result) - 1 while index >= 0: if result[index] < 9: result[index] += 1 return result result[index] = 0 index -= 1 return result print(add_one_broken([1, 2, 3]), add_one_broken([1, 2, 9]), add_one_broken([9, 9]))Read the constraints first and let them tell you what complexity is expected. Derive the approach, implement it, run the tests, and submit when it passes.
Read the constraints first and let them tell you what complexity is expected. Derive the approach, implement it, run the tests, and submit when it passes.