Very long word

Report a typo

Implement a method that returns the longest word in a collection via an iterator. If the collection is empty, return ' '.

Sample Input 1:

cat kotlin programming python

Sample Output 1:

programming
Write a program in Kotlin
fun findLongestByIterator(strIterator: Iterator<String>): String {
// write your code here
}

fun main() {
val words: List<String> = readLine()!!.split("\\s+".toRegex())
println(findLongestByIterator(words.iterator()))
}
___

Create a free account to access the full topic