I’ve written the code for problem CHHAPPY. It should work fine. It runs under the given time limit but gives wrong answer for 3 out of 4 test cases. Please have a look at this code and lemme know what is the problem with this code…
My approach is that I make a structure array which is sorted version of A but with its initial indices attached with it. I also check which indices are present in A and mark them valid. Then I check under result function whether any 2 valid elements of structure are equal or not.
Here’s link to my code: