/**
 * The given code snippet takes a tuple of photo data, where each element of the tuple is a nested tuple that represents a photo's name, tags, and ratings.
 * Your task is to implement a function that returns a list of tags that are common to all the photos in the photo_data.
 * However, you should use short-circuiting with if-else statements and indexing and slicing tuples to make your solution more efficient.
 *
 * Example:
 * findCommonTags(listOf(
 *     Triple("photo1", listOf("nature", "landscape"), 4),
 *     Triple("photo2", listOf("nature", "portrait"), 5),
 *     Triple("photo3", listOf("nature", "landscape", "portrait"), 3)
 * ))
 * Output: ['nature']
 */
fun findCommonTags(photoData: List<Triple<String, List<String>, Int>>): List<String> {

    if (photoData.isEmpty()) {
        return emptyList()
    }

    var commonTags = photoData[0].second.toMutableList() // Extracting the tags of the first photo

    for (i in 1 until photoData.size) {
        // Using short-circuiting with if-else to check common tags for each photo
        commonTags.retainAll { tag -> photoData[i].second.contains(tag) }

        if (commonTags.isEmpty()) { // If commonTags becomes empty
            break
        }
    }

    return commonTags
}
/**
 * The given code snippet takes a tuple of photo data, where each element of the tuple is a nested tuple that represents a photo's name, tags, and ratings.
 * Your task is to implement a function that returns a list of tags that are common to all the photos in the photo_data.
 * However, you should use short-circuiting with if-else statements and indexing and slicing tuples to make your solution more efficient.
 *
 * Example:
 * findCommonTags(listOf(
 *     Triple("photo1", listOf("nature", "landscape"), 4),
 *     Triple("photo2", listOf("nature", "portrait"), 5),
 *     Triple("photo3", listOf("nature", "landscape", "portrait"), 3)
 * ))
 * Output: ['nature']
 */
fun findCommonTags(photoData: List<Triple<String, List<String>, Int>>): List<String> {
/**
 * The given code snippet takes a tuple of photo data, where each element of the tuple is a nested tuple that represents a photo's name, tags, and ratings.
 * Your task is to implement a function that returns a list of tags that are common to all the photos in the photo_data.
 * However, you should use short-circuiting with if-else statements and indexing and slicing tuples to make your solution more efficient.
 *
 * Example:
 * findCommonTags(listOf(
 *     Triple("photo1", listOf("nature", "landscape"), 4),
 *     Triple("photo2", listOf("nature", "portrait"), 5),
 *     Triple("photo3", listOf("nature", "landscape", "portrait"), 3)
 * ))
 * Output: ['nature']
 */
fun findCommonTags(photoData: List<Triple<String, List<String>, Int>>): List<String> {

    if (photoData.isEmpty()) {
        return emptyList()
    }

    var commonTags = photoData[0].second.toMutableList() // Extracting the tags of the first photo

    for (i in 1 until photoData.size) {
        // Using short-circuiting with if-else to check common tags for each photo
        commonTags.retainAll { tag -> photoData[i].second.contains(tag) }

        if (commonTags.isEmpty()) { // If commonTags becomes empty
            break
        }
    }

    return commonTags
}