Sobes.tech
Junior — Middle+

Get unique strings sorted by frequency of occurrence

livecode

Task condition

Create a function that takes an array of strings and returns a new array containing only the unique values from the original array. The elements should be sorted in descending order of their frequency in the original set (from most common to least common). When frequencies are equal, the order can be arbitrary.

Example:

input_data = ["apple", "banana", "apple", "orange", "banana", "banana"]
# result: ["banana", "apple", "orange"]

The function should operate in O(n log n) time or better, where n is the length of the input array.