What is the approach for this question?

i am really very stuck in this array section please help

the approach is as follows:
take the number x as an array
starting from the msb, invert only those digits which are greater than 5 (ex: invert 6 to 4)
return the new x

i was able to solve this problem but is shows “Run Error” for test Case 2 and 3 https://ide.codingblocks.com/s/369953

Check your indexes they are going out of bounds