/**
 * Given a contract string and a set of lawyers, return a formatted string indicating whether all lawyers have
 * reviewed the contract or not.
 *
 * @param contract The contract to be validated.
 * @param lawyers The set of lawyers who should review the contract.
 * @return A formatted string indicating whether all lawyers have reviewed the contract or not.
 *
 * Example:
 * validateContract("This is a contract.", setOf("Lawyer A", "Lawyer B", "Lawyer C"))
 * Output: "Lawyer A, Lawyer B, and Lawyer C need to review the contract."
 */
fun validateContract(contract: String, lawyers: Set<String>): String {

    val reviewedBy = lawyers.filter { it in contract }.toSet()

    return when {
        reviewedBy.size == lawyers.size -> "All lawyers have reviewed the contract."
        else -> {
            val nonReviewed = lawyers - reviewedBy
            return when {
                nonReviewed.size == 1 -> "${nonReviewed.first()} needs to review the contract."
                else -> {
                    val reviewedStr = reviewedBy.sorted().joinToString(", ")
                    "${reviewedStr.dropLast(2)} and ${reviewedStr.takeLast(2)} need to review the contract."
                }
            }
        }
    }
}
/**
 * Given a contract string and a set of lawyers, return a formatted string indicating whether all lawyers have
 * reviewed the contract or not.
 *
 * @param contract The contract to be validated.
 * @param lawyers The set of lawyers who should review the contract.
 * @return A formatted string indicating whether all lawyers have reviewed the contract or not.
 *
 * Example:
 * validateContract("This is a contract.", setOf("Lawyer A", "Lawyer B", "Lawyer C"))
 * Output: "Lawyer A, Lawyer B, and Lawyer C need to review the contract."
 */
fun validateContract(contract: String, lawyers: Set<String>): String {
/**
 * Given a contract string and a set of lawyers, return a formatted string indicating whether all lawyers have
 * reviewed the contract or not.
 *
 * @param contract The contract to be validated.
 * @param lawyers The set of lawyers who should review the contract.
 * @return A formatted string indicating whether all lawyers have reviewed the contract or not.
 *
 * Example:
 * validateContract("This is a contract.", setOf("Lawyer A", "Lawyer B", "Lawyer C"))
 * Output: "Lawyer A, Lawyer B, and Lawyer C need to review the contract."
 */
fun validateContract(contract: String, lawyers: Set<String>): String {

    val reviewedBy = lawyers.filter { it in contract }.toSet()

    return when {
        reviewedBy.size == lawyers.size -> "All lawyers have reviewed the contract."
        else -> {
            val nonReviewed = lawyers - reviewedBy
            return when {
                nonReviewed.size == 1 -> "${nonReviewed.first()} needs to review the contract."
                else -> {
                    val reviewedStr = reviewedBy.sorted().joinToString(", ")
                    "${reviewedStr.dropLast(2)} and ${reviewedStr.takeLast(2)} need to review the contract."
                }
            }
        }
    }
}