/**
 * A zoologist wants to find the endangered species based on their habitat ratings.
 * Each species has a corresponding habitat rating, ranging from 1 to 10.
 *
 * Your task is to create a function that takes in a list of species and their habitat ratings,
 * and returns a list of species that are endangered.
 *
 * The function should find the species that have a habitat rating of less than 5.
 *
 * Additionally, the function should return the species in reverse order based on their indices in the original list.
 *
 * For example, given the following inputs:
 *
 * speciesList = listOf("Polar Bear", "Gorilla", "Elephant", "Tiger", "Rhino")
 * habitatRatings = listOf(8, 6, 3, 9, 2)
 *
 * The function should return:
 * listOf("Rhino", "Tiger", "Elephant")
 *
 * Complete the function to solve this exercise.
 */
fun findEndangeredSpecies(speciesList: List<String>, habitatRatings: List<Int>): List<String> {

    val endangeredSpecies = mutableListOf<String>()

    for (i in speciesList.indices) {
        if (habitatRatings[i] < 5) {
            endangeredSpecies.add(speciesList[speciesList.size - 1 - i])
        }
    }

    return endangeredSpecies
}
/**
 * A zoologist wants to find the endangered species based on their habitat ratings.
 * Each species has a corresponding habitat rating, ranging from 1 to 10.
 *
 * Your task is to create a function that takes in a list of species and their habitat ratings,
 * and returns a list of species that are endangered.
 *
 * The function should find the species that have a habitat rating of less than 5.
 *
 * Additionally, the function should return the species in reverse order based on their indices in the original list.
 *
 * For example, given the following inputs:
 *
 * speciesList = listOf("Polar Bear", "Gorilla", "Elephant", "Tiger", "Rhino")
 * habitatRatings = listOf(8, 6, 3, 9, 2)
 *
 * The function should return:
 * listOf("Rhino", "Tiger", "Elephant")
 *
 * Complete the function to solve this exercise.
 */
fun findEndangeredSpecies(speciesList: List<String>, habitatRatings: List<Int>): List<String> {
/**
 * A zoologist wants to find the endangered species based on their habitat ratings.
 * Each species has a corresponding habitat rating, ranging from 1 to 10.
 *
 * Your task is to create a function that takes in a list of species and their habitat ratings,
 * and returns a list of species that are endangered.
 *
 * The function should find the species that have a habitat rating of less than 5.
 *
 * Additionally, the function should return the species in reverse order based on their indices in the original list.
 *
 * For example, given the following inputs:
 *
 * speciesList = listOf("Polar Bear", "Gorilla", "Elephant", "Tiger", "Rhino")
 * habitatRatings = listOf(8, 6, 3, 9, 2)
 *
 * The function should return:
 * listOf("Rhino", "Tiger", "Elephant")
 *
 * Complete the function to solve this exercise.
 */
fun findEndangeredSpecies(speciesList: List<String>, habitatRatings: List<Int>): List<String> {

    val endangeredSpecies = mutableListOf<String>()

    for (i in speciesList.indices) {
        if (habitatRatings[i] < 5) {
            endangeredSpecies.add(speciesList[speciesList.size - 1 - i])
        }
    }

    return endangeredSpecies
}