Skip to content

Instantly share code, notes, and snippets.

@DjangoLC
Created November 10, 2023 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DjangoLC/a660356414d343ad9b0694f3f811c403 to your computer and use it in GitHub Desktop.
Save DjangoLC/a660356414d343ad9b0694f3f811c403 to your computer and use it in GitHub Desktop.
solution
package basics
fun main() {
val str ="no todos los carros son azules todos los carros son azules lo sabias sabias"
findRepeatedWords(str)
}
fun findRepeatedWords(str: String) {
val split = str.split(" ")
val map = mutableMapOf<String, Int>()
split.forEach { word ->
if (map.containsKey(word)) {
val count = map.getValue(word) + 1
map[word] = count
} else {
map[word] = 1
}
}
println(map.filter { it.value > 1 }.keys.joinToString(", "))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment