BEATS 100% PYTHON USERS- EASY LOOPING METHOD
ApproachWe first count the frequencies of the characters present in strings and have it in our list l. Next, We are going to loop until sum of the list l become
# Approach
<!-- Describe your approach to solving the problem. -->
![leetcode1370.PNG](https://assets.leetcode.com/users/images/98e794c7-c80a-4ed9-9ac4-05b60aa6c006_1728817818.2487426.png)
We first count the frequencies of the characters present in string `s` and have it in our list `l`. Next, We are going to loop until sum of the list `l` becomes **0** (We'll see why we have this as our loop conditon). Inside the loop we loop the alphabets in forward and reverse orders append a character to `ans` when the condition `if l[i]:` is satisfied, This looping processes will allow us to follow up the steps from 1-6, and for the other part, i.e, We might need to do the steps again starting from 1 to 6 or so on repeatedly... Therefore we decremenet the frequencies of the characters each time when appended and thus making sure that the loop ends when all frequencies becomes **0** i.e, `sum(l)!=0` becomes ***False***, Finally we return our answer `ans`.
Hope this helps.
# Code
```python []
class Solution(object):
    def sortString(self, s):
        l=[0]*26
        for ch in s:
            l[ord(ch)-97]+=1
        ans=''
        while sum(l)!=0:
            for i in range(0,26):
                if l[i]:
                    ans+=chr(i+97)
                    l[i]-=1
            for i in range(25,-1,-1):
                if l[i]:
                    ans+=chr(i+97)
                    l[i]-=1
        return ans
```
```python3 []
class Solution:
    def sortString(self, s: str) -> str:
        l=[0]*26
        for ch in s:
            l[ord(ch)-97]+=1
        ans=''
        while any(l):
            for i in range(0,26):
                if l[i]:
                    ans+=chr(i+97)
                    l[i]-=1
            for i in range(25,-1,-1):
                if l[i]:
                    ans+=chr(i+97)
                    l[i]-=1
        return ans
```
['Python', 'Python3']