Code: 03


 Question 3

 

Group of numbers

You are given an array a that contains N integers. All the integers in the array may not be distinct.

 

The numbers of repetitions of each integer in the array is represented by ri. your task is to print the integers in the decreasing order of their occurrence in the array.

Note

·        If r­I >rj then a­I must be printed before aj.

·        If ri==rj then among ai and a­j whichever has a larger value is printed first.

Here, rand rj are the numbers of repetitions of integers ai and aj  in the array.

Example

Consider a array = [4,4,4,2,2,1,3,3,1,5]. Now the frequencies are :

1 -> 2

2 -> 2

3 -> 2

4 -> 3

5 -> 1

So we have to arrange in the decreasing order of their frequencies. So 4(1,2,3)5. Now we have to take care of numbers having same frequencies. So answer is 4 1 2 3 5.

 

Note: please read the sample explanation carefully to understand the task that you have to perform

Function description

Complete the solve function provided in the editor. This function takes the following2 parameters and returns the answer vector sequence:

·        N: represents the size of the array

·        A: represents the array

Input format

·        The first line contains an integer

·        The second line contains N space centered integers representing the elements of the array a

Output format

Print the space separated integers in the decreasing order of their occurrence in the array. The output must be printed in a single line.

Constraints

1≤ N ≤ 1000

1≤ ai ≤ 1000



 

Explanation

In the given sample there are 3 distinct numbers 1, 2 and 6 with ri values as 2, 2 and 1. So as per the task given, 2 comes before 1 as it has the same ri but its larger than 1. 1 comes before 6 as its ri value is greater than 6. The output will be

216

No comments:

Post a Comment