January 2022 enrollments are closed and the course commences on 8th of January, 2022. For future cohorts Join the waitlist →

```
class Solution {
public:
vector<int> plusOne(vector<int> &digits) {
int n = digits.size();
int sum = 0;
int carry = 1;
for( int i = n-1 ; i >= 0 ; i-- ) {
sum = (carry + digits[i]) % 10;
carry = (carry + digits[i]) / 10;
digits[i] = sum;
}
if( carry == 0 ) {
return digits;
}
else {
digits.insert(digits.begin(),carry);
return digits;
}
}
};
```

I write essays on various engineering topics and share it through my weekly newsletter 👇