Help me in solving LPYAS165 problem

My issue

code

My code

v

Learning course: Roadmap to 3*
Problem Link: Pattern Wave in Roadmap to 3*