Solution in kotlin:
fun main() { val colors = arrayOf(10, 20, 20, 10, 10, 30, 50, 10, 20) var pairs = 0 val colorFrequencies: MutableMap<Int, Int> = mutableMapOf() colors.forEach { color -> val count = colorFrequencies.getOrDefault(color, 0) colorFrequencies[color] = count+1 } colorFrequencies.forEach { entry -> pairs += entry.value / 2 } println(pairs) }
Basically you store the frequency of each colour in a map, then you perform division by 2 on each entry value
Very interesting. I can see some syntax similarities between JavaScript and Kotlin. Thanks for sharing.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Solution in kotlin:
Basically you store the frequency of each colour in a map, then you perform division by 2 on each entry value
Very interesting. I can see some syntax similarities between JavaScript and Kotlin. Thanks for sharing.