Help regarding Hill Sequence November long challenge

Hi! Can you tell me why my solution is wrong? I have followed every detail still the answer is not being accepted. Please suggest any mistakes or corner cases.
https://www.codechef.com/viewsolution/53906044

.

Thanks for forwarding my reply here. But my answer was for Weird Palindrome and you attached my reply to Hill Sequence.
Nevermind, the approach for the problem that i would have used is

  1. Sort the array
  2. If any character is appearing more than twice, the straightaway print -1
  3. Traverse through the array, if the character is same as the next one (For eg. s[i]==s[i+1]) then print the character once and store the next same character into another array. In this step print only the repeated characters once. If the character has no same character (For eg s[i]!=s[i+1]) then store that element in the array in which multiple characters were also getting stored
  4. Sort the another array in descending order
  5. Print the array

Illustration

Array is [1 , 2 , 7 , 4 , 4 , 6 , 5]

  1. Sort the Array [1 , 2 , 4 , 4 , 5 , 6 , 7]
  2. Print the multiple appearing character and store other letters once in array2 Display = 4 && array2 = [1 , 2 , 4 , 5 , 6 , 7|
  3. Reverse sort the array [7 , 6 , 5 , 4 , 2 , 1]
  4. Print the array Display = 4 7 6 5 4 2 1
1 Like

Sorry for the mistake :sweat_smile:

1 Like

No problem fam

Lol someone clear out my mistake too.

Hey! I have found two mistakes in your code.

  • You need to handle the case for n == 1 at the beginning itself, as your code seems to be giving out of bounds exception for that.

  • There seems to be something wrong with the if statement at line 42.
    You can use the following input to debug that :-

1
8
5 4 2 1 3 3 3 8

*Your’s modified AC Code

2 Likes

Oh! Thanks a lot…I was just missing the n=1 case. Line 42 was correct earlier and made it wrong to make the code shorter. But it’s all fine now.