Sort array by frequency

Company: Scienaptic AI_11oct

Difficulty: medium

Problem Statement

Sort array by frequency Problem Description You are given a list numArray of n integers. Rearrange the list so that the values that occur fewer times come first. The order is decided by two rules: A value that occurs fewer times in numArray is placed before a value that occurs more times. When two different values occur the same number of times, the larger value is placed first. Every copy of a value is kept, so the result is a rearrangement of numArray and has exactly n elements. Because all copies of one value share the same frequency, they always end up next to each other. Implement sortArray(numArray) , which returns the rearranged list. Input Format Read from standard input. n numArray[0] numArray[1] ... numArray[n-1] Line 1 contains the integer n , the number of elements. Line 2 contains the n integers, separated by single spaces. (inferred -- the source shows only a function signature; this two-line stdin layout is used.) Output Format Print the n rearranged integers on a single