/**
 * Write a function that takes in a list of tuples and an index, and returns a list of unique elements that appear in the second element of each tuple at the given index.
 *
 * @param tupleList A list of tuples.
 * @param index An integer representing the index to access the elements of the tuples.
 * @return A list of unique elements that appear in the second element of each tuple at the given index.
 *
 * Example:
 * intersection([(1, 'a'), (2, 'b'), (3, 'c'), (4, 'a')], 1) -> ['a', 'b', 'c']
 */
fun intersection(tupleList: List<Pair<Int, String>>, index: Int): List<String> {

    // Create an empty set to store unique elements
    val uniqueElements = mutableSetOf<String>()

    // Iterate over each tuple in the list
    for (tuple in tupleList) {
        // Access the second element of the tuple at the given index
        val element = tuple.second

        // Check if the element is not already in the set
        if (element !in uniqueElements) {
            // Add the element to the set
            uniqueElements.add(element)
        }
    }

    // Convert the set to a list and return the result
    return uniqueElements.toList()
}
/**
 * Write a function that takes in a list of tuples and an index, and returns a list of unique elements that appear in the second element of each tuple at the given index.
 *
 * @param tupleList A list of tuples.
 * @param index An integer representing the index to access the elements of the tuples.
 * @return A list of unique elements that appear in the second element of each tuple at the given index.
 *
 * Example:
 * intersection([(1, 'a'), (2, 'b'), (3, 'c'), (4, 'a')], 1) -> ['a', 'b', 'c']
 */
fun intersection(tupleList: List<Pair<Int, String>>, index: Int): List<String> {
/**
 * Write a function that takes in a list of tuples and an index, and returns a list of unique elements that appear in the second element of each tuple at the given index.
 *
 * @param tupleList A list of tuples.
 * @param index An integer representing the index to access the elements of the tuples.
 * @return A list of unique elements that appear in the second element of each tuple at the given index.
 *
 * Example:
 * intersection([(1, 'a'), (2, 'b'), (3, 'c'), (4, 'a')], 1) -> ['a', 'b', 'c']
 */
fun intersection(tupleList: List<Pair<Int, String>>, index: Int): List<String> {

    // Create an empty set to store unique elements
    val uniqueElements = mutableSetOf<String>()

    // Iterate over each tuple in the list
    for (tuple in tupleList) {
        // Access the second element of the tuple at the given index
        val element = tuple.second

        // Check if the element is not already in the set
        if (element !in uniqueElements) {
            // Add the element to the set
            uniqueElements.add(element)
        }
    }

    // Convert the set to a list and return the result
    return uniqueElements.toList()
}