11 April 2017

isBeautifulString

My solution:
bool isBeautifulString(string inputString) 
{
    var sorted = Enumerable.Range('a', inputString.Max(c => c) - 'a' + 1).Select(i => (char)i).ToArray();
    for (var i = 1; i < sorted.Length; i++)
        if (inputString.Count(c => c == sorted[i]) > inputString.Count(c => c == sorted[i - 1]))
            return false;

    return true;
}
Terms of use: http://stackoverflow.com/a/314508 by http://stackoverflow.com/users/4685/pop-catalin, modified under https://creativecommons.org/licenses/by-sa/3.0/.

Previous Next