How to find missing alphabet characters from a string in Scala

1 Answer

0 votes
def getMissingAlphabetChars(input: String): Seq[Char] = {
  // Full alphabet as a Set
  val alphabet: Set[Char] = ('a' to 'z').toSet

  // Normalize input: lowercase + keep only letters a–z
  val present: Set[Char] =
    input.toLowerCase.filter(_.isLetter).filter(_.isLower).toSet

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

@main def run(): Unit = {
  val missing = getMissingAlphabetChars("Scala Programming")
  
  println(missing)
}



/*
run:

List(b, d, e, f, h, j, k, q, t, u, v, w, x, y, z)

*/

 



answered Mar 8 by avibootz
...