Skip to content

Instantly share code, notes, and snippets.

@toantran-ea
Created December 25, 2019 05:07
Show Gist options
  • Save toantran-ea/97d5a9aafccc14a251d595fa46dbb75e to your computer and use it in GitHub Desktop.
Save toantran-ea/97d5a9aafccc14a251d595fa46dbb75e to your computer and use it in GitHub Desktop.
Kotlin Solution for Sparse Array problem
// Complete the matchingStrings function below.
fun matchingStrings(strings: Array<String>, queries: Array<String>): Array<Int> {
val result = Array<Int>(queries.size) { 0 }
queries.forEachIndexed { index, item ->
result[index] = strings.count { item == it }
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment