The Empire strikes back

Report a typo

The Resistance is organizing ships to confront the Empire. R2D2 has a list with the ships. The Resistance will attack using the following strategy: the last ship will be the first. Please help R2D2 print the ships in the correct order for the combat where the last ship will be the first.

Sample Input 1:

XWing-100 YWing-200 TWing-50 TIEFighter-300

Sample Output 1:

TIEFighter-300 TWing-50 YWing-200 XWing-100
Write a program in Kotlin
data class Ship(val name: String, val ammunition: Int) {
override fun toString(): String {
return "$name-$ammunition"
}
}

fun fixTheQueue(input: String): ArrayDeque<Ship> {
// Convert input to list of ships
val shipsList = input.split(" ").map {
val parts = it.split("-")
Ship(parts[0], parts[1].toInt())
}

// Use ArrayDeque to reorganize a list
// Put your code here

return shipsQueue
}
___

Create a free account to access the full topic