Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

its an hackerrank challlenge and the solution needs to pass all the test cases to be correct image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago