Leetcode-plus one question

Question:https://leetcode.com/problems/plus-one/
Solution:https://ide.codingblocks.com/s/56265

I am not able to figure out the bug in my code.pl help

Firstly, you have accessed a[n] (line 23) which is not defined.
Also, you have not considered the case when the number can be of the sort 999.

yeah i know…
can you please help me with including that case?
i could not figure it out

Follow this link for complete code

Hey Shraddha Shaligram, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required. And please mark your doubts as resolved in your course’s “Ask Doubt” section, when your doubt is resolved.