Kotlin Sliding window O(n)
\n\nfun longestBeautifulSubstring(word: String): Int {\n\t// edge cases\n    if (word.length < 5) {\n        return 0\n    }\n    if (word.toList().distinct().s
```\n\nfun longestBeautifulSubstring(word: String): Int {\n\t// edge cases\n    if (word.length < 5) {\n        return 0\n    }\n    if (word.toList().distinct().size < 5) {\n        return 0\n    }\n\t\n    val characters = word.toCharArray()\n    var counter = 1\n    var maxValue = 0\n    var currentLength = 1\n\t\n    for (index in 1 until characters.size) {\n        when {\n            characters[index - 1] == characters[index] -> currentLength++\n            characters[index - 1] < characters[index] -> {\n                currentLength++\n                counter++\n            }\n            else -> {\n                currentLength = 1\n                counter = 1\n            }\n        }\n        if (counter == 5) maxValue = max(maxValue, currentLength)\n    }\n    return maxValue\n}\n```
['Sliding Window', 'Kotlin']