DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 968,873 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Achilonu Chinwendu Faustina
Achilonu Chinwendu Faustina

Posted on

DAY 5 CODE CHALLENGE

SORT CHARACTERS BY FREQUENCY

A string s= tree is given to rearrange in decreasing order of frequency such that, the output will be "eetr" or "eert".

APPROACH
Check the frequency of the characters;
e = 2;
t = 1;
r = 1;
writing this in decreasing order of frequency;
output = eetr
or
output = eert
Here r and t are of the same frequency, therefore anyone can be written first.

PROCEDURE

  • I saved the frequencies in a hashtable.

  • I sorted them (frequencies) in decreasing order.

  • I rebuilt the strings based on frequencies.

OUTCOME

Image description

Top comments (0)

Need a better mental model for async/await?

Check out this classic DEV post on the subject.

β­οΈπŸŽ€ JavaScript Visualized: Promises & Async/Await

async await