/**
 * Given a starting index and a list of historical events,
 * find the last event that occurred at that index.
 *
 * @param startIndex The starting index.
 * @param historyList List of historical events.
 * @return The index of the last event occurred at the given startIndex.
 *
 * Example:
 * findLastElement(2, listOf("Event1", "Event2", "Event3", "Event2")) // Output: 3
 * findLastElement(0, listOf("Event1", "Event2", "Event3", "Event2")) // Output: 0
 */
fun findLastElement(startIndex: Int, historyList: List<String>): Int {

    for (i in startIndex downTo 0) {
        if (historyList[i] == historyList[startIndex]) {
            return i
        }
    }
    return -1
}
/**
 * Given a starting index and a list of historical events,
 * find the last event that occurred at that index.
 *
 * @param startIndex The starting index.
 * @param historyList List of historical events.
 * @return The index of the last event occurred at the given startIndex.
 *
 * Example:
 * findLastElement(2, listOf("Event1", "Event2", "Event3", "Event2")) // Output: 3
 * findLastElement(0, listOf("Event1", "Event2", "Event3", "Event2")) // Output: 0
 */
fun findLastElement(startIndex: Int, historyList: List<String>): Int {
/**
 * Given a starting index and a list of historical events,
 * find the last event that occurred at that index.
 *
 * @param startIndex The starting index.
 * @param historyList List of historical events.
 * @return The index of the last event occurred at the given startIndex.
 *
 * Example:
 * findLastElement(2, listOf("Event1", "Event2", "Event3", "Event2")) // Output: 3
 * findLastElement(0, listOf("Event1", "Event2", "Event3", "Event2")) // Output: 0
 */
fun findLastElement(startIndex: Int, historyList: List<String>): Int {

    for (i in startIndex downTo 0) {
        if (historyList[i] == historyList[startIndex]) {
            return i
        }
    }
    return -1
}