# #I4G10DaysOfCodeChallenge  - Day 5

## Question
 LeetCode problem [451. Sort Characters By Frequency](https://leetcode.com/problems/sort-characters-by-frequency) 

Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.    
*Return the sorted string. If there are multiple answers, return any of them.*

**Constraints:**       
- ``` 1 <= s.length <= 5 * 10^5 ```
- s consists of uppercase and lowercase English letters and digits.

That's enough intro, let's get to it!

#### Step 1: Initiate a dictionary of characters present and loop
```python
class Solution:
    def frequencySort(self, s: str) -> str:
        tracker = #set_to_empty_dictionary
        for each in #list_of_unique_characters_in_s:
            tracker[key] = value #which equals the frequency of "key" in list of s
```       
#### Step 2: Initiate a dictionary of characters present and loop
```python
        tracker =  #sort tracker by value in descending order
        sorted_s = "" #set an empty string to hold sorted strings
        for each in tracker: #iterate each key-value pair in the dictionary
            sorted_s += key*n #add key to sorted_s the number of times it occured
            
        return sorted_s 
```    

#### Highlight of the entire process:
```python
class Solution:
    def frequencySort(self, s: str) -> str:
        tracker = #set_to_empty_dictionary
        for each in #list_of_unique_characters_in_s:
            tracker[key] = value #which equals the frequency of "key" in list of s
        tracker =  #sort tracker by value in descending order
        sorted_s = "" #set an empty string to hold sorted strings
        for each in tracker: #iterate each key-value pair in the dictionary
            sorted_s += key*n #add key to sorted_s the number of times it occured
            
        return sorted_s 
``` 

Hope you find this helpful.


Happy coding!

Kindly follow me on [Twitter](https://www.twitter.com/boffinbee)  ||  [LinkedIn](https://www.linkedin.com/in/abolarinwa-quadri-8b16b5195)
