Mutable List

Report a typo

We have a function names. When the function is called, a list namesList: List<String> is passed through the parameters. Implement counting the number of names in the input list.

Write the result of the calculation to the nameCount list in the following format: The name Vasya is repeated 2 times.

For example, the input list contains the following names: "Vasya", "Olga", "Vasya", "Dima", "Masha", "Vasa", "Olga".

As a result of the function, the nameCount list will have the following contents:

"The name Vasya is repeated 2 times"

"The name Olga is repeated 2 times"

"The name Dima is repeated 1 times"

"The name Masha is repeated 1 times"

"The name Vasa is repeated 1 times"

You can solve this problem using only lists, but if you want to use Map, you can read more in the topics: Map collection and MutableMap.

Write a program in Kotlin
fun names(namesList: List<String>): List<String> {
var count = 0
val nameCount = mutableListOf<String>()
//
// add your code here
//
return nameCount
}
___

Create a free account to access the full topic