Why is this code not working?

Why is this code not working?

For this Question

One Test Case is creating issue that is [1] and n=1.

And Please tell if any other approach available.