Longest Zig-Zag subsequence getting wrong ans

I am getting WA in Longest Zig-Zag subsequence problem.

Here is my solution, I need help in finding what is wrong with my code.

Brief about my approach:
For every element in the array I have calculated length of the longest Zig-Zag subsequence starting from that the element and taking max of length for all the elements.

Note:
I know this is going to give TLE, but I want to learn what’s wrong with this.

@vijju123 @mathecodician @akashbhalotia @aryanc403 @vermashubhang @neo1tech9_7 @alei, guys help me with this.