# 1405. Longest Happy String

[Link](https://leetcode.com/problems/longest-happy-string/)

**Solution**

Always keep the a > b > c, and then decide which character will be put into the result

```java
    
    public String generateString(int a, int b, int c, String aa, String bb, String cc){
        if(b > a){
            return generateString(b, a, c, bb, aa, cc);
        }
        if(c > b){
            return generateString(a, c, b, aa, cc, bb);
        }
        if(a == 0) return "";
        if(b == 0 && c == 0){
            return aa + (a >= 2 ? aa : "");
        }
        int aaCount = Math.min(a, 2); 
        int bbCount = (a-aaCount >= b ? 1 : 0); //if bbCount = 0, means next run will add "bb"
        
        return aa + (aaCount == 2? aa : "") + (bbCount != 0 ? bb : "") + generateString(a-aaCount, b-bbCount, c, aa ,bb ,cc);
    }
    
    
    
    
    public String longestDiverseString(int a, int b, int c) {
        return generateString(a, b, c, "a", "b", "c");
    }
```
