6 kyu

Simple frequency sort

2,292 of 5,545KenKamau

Description:

In this kata, you will sort elements in an array by decreasing frequency of elements. If two elements have the same frequency, sort them by increasing value.

solve([2,3,5,3,7,9,5,3,7]) = [3,3,3,5,5,7,7,2,9]
-- We sort by highest frequency to lowest frequency.
-- If two elements have same frequency, we sort by increasing value.
solve({2,3,5,3,7,9,5,3,7}) == {3,3,3,5,5,7,7,2,9}
// We sort by highest frequency to lowest frequency.
// If two elements have same frequency, we sort by increasing value.
Solution.sortByFrequency(new int[]{2, 3, 5, 3, 7, 9, 5, 3, 7});
// Returns {3, 3, 3, 5, 5, 7, 7, 2, 9}
// We sort by highest frequency to lowest frequency.
// If two elements have same frequency, we sort by increasing value.

More examples in test cases.

Good luck!

Please also try Simple time difference

Algorithms
Sorting
Arrays

Stats:

CreatedFeb 21, 2018
PublishedFeb 21, 2018
Warriors Trained11429
Total Skips311
Total Code Submissions22514
Total Times Completed5545
Python Completions2292
JavaScript Completions2111
Haskell Completions108
Ruby Completions218
Nim Completions10
C++ Completions319
Java Completions435
Rust Completions119
Clojure Completions24
Go Completions92
COBOL Completions6
λ Calculus Completions4
Total Stars236
% of votes with a positive feedback rating95% of 839
Total "Very Satisfied" Votes764
Total "Somewhat Satisfied" Votes60
Total "Not Satisfied" Votes15
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • KenKamau Avatar
  • Unnamed Avatar
  • raulbc777 Avatar
  • imjasonmiller Avatar
  • JohanWiltink Avatar
  • Voile Avatar
  • rsa Avatar
  • hobovsky Avatar
  • username0 Avatar
  • kvbc Avatar
  • Reargem Avatar
  • akar-0 Avatar
  • saudiGuy Avatar
Ad