✅ Scala: easy solution using groupMapReduce and withDefault
Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\nscala\nobject Solution {\n\n  def digitCount(num: String): Boolean = {\n    val counts 
# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```scala\nobject Solution {\n\n  def digitCount(num: String): Boolean = {\n    val counts = num.groupMapReduce(_.asDigit)(_ => 1)(_ + _).withDefault(_ => 0)\n\n    for (i <- num.indices if counts(i) != num(i).asDigit) {\n      return false\n    }\n\n    true\n  }\n\n}\n```
['Hash Table', 'Counting', 'Enumeration', 'Scala']