> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/05-09-2022-1370.-increasing-decreasing-string.md).

# 05/09/2022  1370. Increasing Decreasing String

Method:&#x20;

Method: first count the frequency of all charcaters present inside the given input text. then we take the frequency until our resulting string < len(input string). first we go from a - > z and check whther we have a frequency > 0, if yes, then we update our result and decrease the frequency. same way, we do z -> a and check the same as above and append to the result. finally this result will give us the answe according to the algorithm provided in the

```
// Some code
class Solution {
    public String sortString(String s) {
        if (s == null || s.length() == 0) return s;
        int[] letter = new int[26];
        
        //count the frequency
        for (char ch: s.toCharArray()){
            letter[ch - 'a']++;
        }
        
        StringBuilder sb = new StringBuilder();
        
        while(sb.length() < s.length()){// stuck here.
            for (int i = 0; i < 26; i++){
                if (letter[i] > 0){
                    sb.append((char)(i + 'a'));
                    letter[i]--;
                }
            }
            
            for (int i = 25; i >= 0; i--){
                if (letter[i] > 0){
                    sb.append((char)(i + 'a'));
                    letter[i]--;
                }
                
            }
        }
        return sb.toString();
        
    }
}
```
