its an hackerrank challlenge and the solution needs to pass all the test cases to be correct
Palindromic Sort Zoey loves marbles, for her birthday her father has given her n marbles which are comprised of m unique types. Zoey wants to display her marbles in her room but first wants to sort them using what Zoey calls her Palindromic Frequency Sort. The Palindromic Frequency Sort sorts elements based on their frequency. Lower frequencies precede higher frequencies, and in the case of a tie, then the lower numbered marble precedes the higher numbered marble. For example, if there were 3 types of marbles, and there were 10 of type 1, and 5 of types 2 and 3, then in ascending order, they would be arranged as Type 2, Type 3, Type1 In Zoey's Palindromic Frequency Sort, the element with the largest frequency is placed at the center of the ordering. Then in descending order of frequency ordering described, elements are placed alternatingly on the right, then the left of the elements already placed Example: [7,2,9,1,4,7,2,6,5,10,6,9,2,1,4,2,6,4,10,6,1,7,1,7,2 Type 1 2 34 5 6789 10 Freq 4 50 3 440 2 2 Palindrome Frequency Sort Phase 1: [2,2,2,2,2] Phase 2: [6,6,6,6,2,2,2,2,2,7,7,7,7 Phase 3: [4,4,4,6,6,6,6,2,2,2,2,2,7,7,7,7,1,1,1,1 Phase 4: [9,9,4,4,4,6,6,6,6,2,2,2,2,2,7,7,7,7,1,1,1,1,10,10] Phase 5: [9,9,4,4,4,6,6,6,6,2,2,2,2,2,7,7,7,7,11,1,1,10,10,5] Given the set of marbles that Zoey received, put them in palindromic frequency sorted order, and then answer q queries about what type of marble is located at each queried position. Input Format The first line contains a single integers n. The following line contain n space separated integers A for 0-i-n The next line contains a single integer q The following line contains q space separated integers Qi for 1i q denoting the index queries to be answered. Palindromic Sort Zoey loves marbles, for her birthday her father has given her n marbles which are comprised of m unique types. Zoey wants to display her marbles in her room but first wants to sort them using what Zoey calls her Palindromic Frequency Sort. The Palindromic Frequency Sort sorts elements based on their frequency. Lower frequencies precede higher frequencies, and in the case of a tie, then the lower numbered marble precedes the higher numbered marble. For example, if there were 3 types of marbles, and there were 10 of type 1, and 5 of types 2 and 3, then in ascending order, they would be arranged as Type 2, Type 3, Type1 In Zoey's Palindromic Frequency Sort, the element with the largest frequency is placed at the center of the ordering. Then in descending order of frequency ordering described, elements are placed alternatingly on the right, then the left of the elements already placed Example: [7,2,9,1,4,7,2,6,5,10,6,9,2,1,4,2,6,4,10,6,1,7,1,7,2 Type 1 2 34 5 6789 10 Freq 4 50 3 440 2 2 Palindrome Frequency Sort Phase 1: [2,2,2,2,2] Phase 2: [6,6,6,6,2,2,2,2,2,7,7,7,7 Phase 3: [4,4,4,6,6,6,6,2,2,2,2,2,7,7,7,7,1,1,1,1 Phase 4: [9,9,4,4,4,6,6,6,6,2,2,2,2,2,7,7,7,7,1,1,1,1,10,10] Phase 5: [9,9,4,4,4,6,6,6,6,2,2,2,2,2,7,7,7,7,11,1,1,10,10,5] Given the set of marbles that Zoey received, put them in palindromic frequency sorted order, and then answer q queries about what type of marble is located at each queried position. Input Format The first line contains a single integers n. The following line contain n space separated integers A for 0-i-n The next line contains a single integer q The following line contains q space separated integers Qi for 1i q denoting the index queries to be answered