Skip to content

AmmarALHasanat/JsQuestionSolution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

JsQuestionSolution

Q1) frequencySort

Given an array of integers, create a 2-dimensional array where the first element is a distinct value from the array and the second element is that value's frequency within the array.
Sort the resulting array descending by frequency.
If multiple values have the same frequency, they should be sorted ascending.

Example

arr = [3, 3, 1, 2, 1]

There are two values, 3 and 1, each with a frequency of 2, and one value 2 with a frequency of 1: [[3, 2], [1, 2], [2, 1]]
Sort the 2-dimensional array descending by frequency: [[3,2], [1, 2], [2, 1]]
Sort the 2-dimensional array ascending by value for values with matching frequencies: [[1,2], [3, 2], [2, 1]]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published