I’m receiving WA on this problem.

Are there any potential test cases where my code fails? Help

Thats a lot of code for a little problem…

May be you could give a hint what is the idea behind it?

Then it would be easyer to see where it fails.

Firstly I store all the differences of consecutive terms of the sequence.

If there is a difference with the most number of occurrence, then I generate a sequence based on it and print it.

Else I brute force and check for all the most frequent differences if the sequence generated by them differ from the given sequence by 1 term and print it.

Edit: I am not sure if this is a good approach though

Since N>=4 there is allways one number of occurence >=2, and mostly two others diff from that one.

So, you have to adjust one of those two others, I think simplest is to adjust the first one.

So, you need one loop to find the diffs, and count the occurences of the diffs.

Then a second loop where you search for the first position where you output all elements of the input array, adjusting the one with the first diff which differs from the diff with the most occurences.

Edit: Ahh, sorry.

Since N>=4 you get a special case for N=4

Input 1, 2, 5, 4

Output should be 1, 2, 3, 4

Diffs are: 1 2 -1

You need to handle this case.

Code is giving correct output for your input.