/**
 * Given a dictionary representing a therapist's records and a list of clients, return a list of common clients sorted in descending order of their ages.
 *
 * @param therapistDict A dictionary with client names as keys and their ages as values.
 * @param clientsList A list of client names to compare with the therapist's records.
 * @return A list of common clients sorted in descending order of their ages.
 */
fun dictionaryListIntersection(therapistDict: Map<String, Int>, clientsList: List<String>): List<String> {

    // Creating a set of client names from the therapist's records
    val therapistClients = therapistDict.keys

    // Extracting common clients between the therapist's records and the provided list
    val commonClients = therapistClients.intersect(clientsList.toSet())

    // Sorting common clients based on their ages in descending order
    val sortedClients = commonClients.sortedByDescending { therapistDict[it] }

    return sortedClients
}
/**
 * Given a dictionary representing a therapist's records and a list of clients, return a list of common clients sorted in descending order of their ages.
 *
 * @param therapistDict A dictionary with client names as keys and their ages as values.
 * @param clientsList A list of client names to compare with the therapist's records.
 * @return A list of common clients sorted in descending order of their ages.
 */
fun dictionaryListIntersection(therapistDict: Map<String, Int>, clientsList: List<String>): List<String> {
/**
 * Given a dictionary representing a therapist's records and a list of clients, return a list of common clients sorted in descending order of their ages.
 *
 * @param therapistDict A dictionary with client names as keys and their ages as values.
 * @param clientsList A list of client names to compare with the therapist's records.
 * @return A list of common clients sorted in descending order of their ages.
 */
fun dictionaryListIntersection(therapistDict: Map<String, Int>, clientsList: List<String>): List<String> {

    // Creating a set of client names from the therapist's records
    val therapistClients = therapistDict.keys

    // Extracting common clients between the therapist's records and the provided list
    val commonClients = therapistClients.intersect(clientsList.toSet())

    // Sorting common clients based on their ages in descending order
    val sortedClients = commonClients.sortedByDescending { therapistDict[it] }

    return sortedClients
}