geeksforgeeks
  • Courses
  • Tutorials
  • Practice
  • Jobs
  • DSA
  • Practice Problems
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • Data Science
  • Machine Learning
  • Courses
  • Linux
  • DevOps
Videos
January 10, 2025 |42.4K Views

Sort elements by frequency

Arrays, Array
 Save  Share  2 Likes
Description
Discussion

Print the elements of an array in the decreasing frequency if 2 numbers have same frequency then print the one which came first.

Examples:  

Input:  arr[] = {2, 5, 2, 8, 5, 6, 8, 8}
Output: arr[] = {8, 8, 8, 2, 2, 5, 5, 6}

Input: arr[] = {2, 5, 2, 6, -1, 9999999, 5, 8, 8, 8}
Output: arr[] = {8, 8, 8, 2, 2, 5, 5, 6, -1, 9999999}

Sort elements by frequency _ Set 1: https://www.geeksforgeeks.org/sort-elements-by-frequency/

Recommendations
Video Thumbnail
12:19
Video Thumbnail
26.4K Views | 10/01/2025...
Find duplicates in O(n) time and O(1) extra space
Video Thumbnail
24:20
Video Thumbnail
12.3K Views | 10/01/2025...
Find four elements that sum to a given value | Set 1 (n^3 solution)
Video Thumbnail
09:16
Video Thumbnail
24.8K Views | 09/01/2025...
Find the first repeating element in an array of integers
Video Thumbnail
10:48
Video Thumbnail
71.7K Views | 08/11/2024...
Array Practice Problems
Video Thumbnail
09:48
Video Thumbnail
283.4K Views | 08/11/2024...
What is Array
Video Thumbnail
09:14
Video Thumbnail
89.2K Views | 22/08/2024...
Find subarray with given sum
Video Thumbnail
11:08
Video Thumbnail
186.6K Views | 22/08/2024...
Array Rotation
Video Thumbnail
08:53
Video Thumbnail
2.1K Views | 13/08/2024...
Find whether an array is subset of another array
Video Thumbnail
08:00
Video Thumbnail
94.7K Views | 13/08/2024...
Merge Two Sorted Arrays
Video Thumbnail
10:24
Video Thumbnail
7.5K Views | 31/07/2024...
Sum of bit differences among all pairs
GeeksforGeeks
location
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
location
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play StoreGFG App on App Store
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • Careers
  • Contact Us
  • Corporate Solution
  • Campus Training Program
  • Explore
  • POTD
  • Practice Problems
  • Connect
  • Blogs
  • Upskill Courses
  • Tutorials
  • Programming Languages
  • DSA
  • Web Technology
  • AI, ML & Data Science
  • DevOps
  • CS Core Subjects
  • GATE
  • School Subjects
  • Software and Tools
  • Courses
  • ML and Data Science
  • DSA and Placements
  • Web Development
  • Data Science
  • Programming Languages
  • DevOps & Cloud
  • GATE
  • MongoDB Certifications
  • Offline Centers
  • Noida
  • Bengaluru
  • Hyderabad
  • Kolkata
  • Preparation Corner
  • Interview Corner
  • Aptitude
  • Puzzles
  • GfG 160
  • System Design
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved