DevJourney · code I wrote while learning

Pattern in user clicks

2 items

README.md

Pattern in user clicks

Single File Programming Question Problem Statement Harsh is analyzing patterns in user clicks. He wants to sort an array based on the frequency of elements in descending order. If two elements have the same frequency, the smaller element should come first. He develops a class FrequencySorter with a method sortByFrequency() that counts occurrences and rearranges the array accordingly using only arrays. Input format : The first line of input contains an integer n, representing the number of elements. The second line of input contains n space-separated integers. Output format : The output displays the frequency-sorted array, printed in a single line (space-separated integers). Refer to the sample output for formatting specifications. Code constraints : The given testcases fall under the following constraints: 1 ≤ n ≤ 1000 −104 ≤ arr[i] ≤ 104 Sample test cases : Input 1 : 6 1 2 2 2 1 1 Output 1 : 1 1 1 2 2 2 Input 2 : 6 1 1 2 2 1 3 Output 2 : 1 1 1 2 2 3