/**
 * Given a list, find the index of the last occurrence of the given item.
 *
 * @param item The item to be found.
 * @param lst The list to search for the item.
 * @return The index of the last occurrence of the item in the list.
 * @throws IllegalArgumentException If the item is not found in the list.
 * @throws IllegalArgumentException If the given argument is not a list.
 *
 * Example:
 * findLastOccurrence("red", listOf("blue", "green", "red", "yellow", "red", "orange")) // Output: 4
 */
fun findLastOccurrence(item: Any, lst: List<Any>): Int {

    if (lst !is List<*>) {
        throw IllegalArgumentException("The given argument is not a list")
    }

    if (item !in lst) {
        throw IllegalArgumentException("Item not found in the list")
    }

    return lst.size - 1 - lst.reversed().indexOf(item)
}
/**
 * Given a list, find the index of the last occurrence of the given item.
 *
 * @param item The item to be found.
 * @param lst The list to search for the item.
 * @return The index of the last occurrence of the item in the list.
 * @throws IllegalArgumentException If the item is not found in the list.
 * @throws IllegalArgumentException If the given argument is not a list.
 *
 * Example:
 * findLastOccurrence("red", listOf("blue", "green", "red", "yellow", "red", "orange")) // Output: 4
 */
fun findLastOccurrence(item: Any, lst: List<Any>): Int {
/**
 * Given a list, find the index of the last occurrence of the given item.
 *
 * @param item The item to be found.
 * @param lst The list to search for the item.
 * @return The index of the last occurrence of the item in the list.
 * @throws IllegalArgumentException If the item is not found in the list.
 * @throws IllegalArgumentException If the given argument is not a list.
 *
 * Example:
 * findLastOccurrence("red", listOf("blue", "green", "red", "yellow", "red", "orange")) // Output: 4
 */
fun findLastOccurrence(item: Any, lst: List<Any>): Int {

    if (lst !is List<*>) {
        throw IllegalArgumentException("The given argument is not a list")
    }

    if (item !in lst) {
        throw IllegalArgumentException("Item not found in the list")
    }

    return lst.size - 1 - lst.reversed().indexOf(item)
}