/**
 * This exercise requires the anthropologist to implement a function that inserts a new name in a sorted list of names.
 *
 * @param nameList A sorted list of names.
 * @param newName The name to be inserted into the list.
 * @return The updated list with the new name inserted.
 *
 * Examples:
 * insertSortedName(listOf("Alice", "Bob", "Tom"), "Charlie") // Output: ["Alice", "Bob", "Charlie", "Tom"]
 * insertSortedName(listOf("Alice", "Bob", "Tom"), "Sam") // Output: ["Alice", "Bob", "Sam", "Tom"]
 */
fun insertSortedName(nameList: List<String>, newName: String): List<String> {

    // Find the correct index to insert the new name
    var index = 0
    while (index < nameList.size && newName > nameList[index]) {
        index++
    }

    // Insert the new name at the correct index
    val updatedList = nameList.toMutableList()
    updatedList.add(index, newName)

    return updatedList
}
/**
 * This exercise requires the anthropologist to implement a function that inserts a new name in a sorted list of names.
 *
 * @param nameList A sorted list of names.
 * @param newName The name to be inserted into the list.
 * @return The updated list with the new name inserted.
 *
 * Examples:
 * insertSortedName(listOf("Alice", "Bob", "Tom"), "Charlie") // Output: ["Alice", "Bob", "Charlie", "Tom"]
 * insertSortedName(listOf("Alice", "Bob", "Tom"), "Sam") // Output: ["Alice", "Bob", "Sam", "Tom"]
 */
fun insertSortedName(nameList: List<String>, newName: String): List<String> {
/**
 * This exercise requires the anthropologist to implement a function that inserts a new name in a sorted list of names.
 *
 * @param nameList A sorted list of names.
 * @param newName The name to be inserted into the list.
 * @return The updated list with the new name inserted.
 *
 * Examples:
 * insertSortedName(listOf("Alice", "Bob", "Tom"), "Charlie") // Output: ["Alice", "Bob", "Charlie", "Tom"]
 * insertSortedName(listOf("Alice", "Bob", "Tom"), "Sam") // Output: ["Alice", "Bob", "Sam", "Tom"]
 */
fun insertSortedName(nameList: List<String>, newName: String): List<String> {

    // Find the correct index to insert the new name
    var index = 0
    while (index < nameList.size && newName > nameList[index]) {
        index++
    }

    // Insert the new name at the correct index
    val updatedList = nameList.toMutableList()
    updatedList.add(index, newName)

    return updatedList
}