How to find missing alphabet characters from a string in Kotlin

1 Answer

0 votes
fun getMissingAlphabetChars(input: String): List<Char> {
    // Full alphabet as a set
    val alphabet = ('a'..'z').toSet()

    // Normalize input: lowercase + keep only letters a–z
    val present = input
        .lowercase()
        .filter { it.isLetter() && it.isLowerCase() }
        .toSet()

    // Difference: alphabet minus present letters
    return (alphabet - present).sorted()
}

fun main() {
    val missing = getMissingAlphabetChars("Kotlin Programming")
    
    println(missing)
}



/*
run:

[b, c, d, e, f, h, j, q, s, u, v, w, x, y, z]

*/

 



answered Mar 8 by avibootz
...