Sentence reversal

Report a typo

Write a function reverseSentence that takes a sentence as a string and returns a new string with the words in reverse order. The function should use StringBuilder, or even better, buildString, for efficient string manipulation.

Sample Input 1:

Hello world! Kotlin is awesome

Sample Output 1:

awesome is Kotlin world! Hello
Write a program in Kotlin
fun reverseSentence(sentence: String): String {
val words = sentence.split(" ")

// Write you code here
}
___

Create a free account to access the full topic