Array - 32: Sort array based on frequency of value (If frequency is same then sort based on value)

preview_player
Показать описание
Solution:
- Iterate all element of array & put in map (key as number & value as frequency)
- Now map has all value with their frequency
- Now use comparator & compare based on their map value
- If frequency is same then compare using value of array element

Time complexity: O(nlogn)
Space Complexity: O(n)

Do Watch video for more info

CHECK OUT CODING SIMPLIFIED

★☆★ VIEW THE BLOG POST: ★☆★

I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 400+ videos.

★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★

★☆★ Send us mail at: ★☆★
Рекомендации по теме
Комментарии
Автор

how does that comp. understand when we code as freq2-freq1 it has to be descending without knowing which of them is greater?

BACSShaileshShettar
Автор

what was that return freq2- freq1 @ 6:16 i'm not quite getting...

godessGOAT
Автор

Where is the playlist for array interview questions

mohammedajazquadri
Автор

you should put which language you're using in title i.e. C++ / Java / Python

ankitjangir
Автор

your code >
input array :{ 10, 7, 10, 11, 10, 7, 6, 5 } ...

output : [10, 10, 10, 7, 7, 5, 6, 11]

11 should not be at the last it should come after 10 .

okfleeaa
join shbcf.ru