link to the ccode
@Bhavya_Goel qcheck for n = 1 your code gives 0 1 1 which is wrong just check this case
@Bhavya_Goel f your doubt is cleared please mark it as resolved