We add all substrings of length k into a hash set. If the size of the hash set is equal to 2^k, we return true. Otherwise, we return false.
fun hasAllCodes(s: String, k: Int): Boolean {
val substrings = HashSet<String>()
for (i in 0..s.length - k) {
substrings.add(s.substring(i, i + k))
}
return substrings.size == 2.0.pow(k).toInt()
}