/**
 * As a psychologist, you need to create a function that modifies a list by adding or removing elements based on certain conditions.
 *
 * Here's how the function should work:
 *
 * - If the length of list1 is not equal to the length of list2, remove the first element from the longer list.
 *
 * - If the length of list1 is equal to the length of list2, append the last element from list2 to list1.
 *
 * - Finally, return the modified list1.
 *
 * Your task is to complete the code by writing the necessary Kotlin code to solve the exercise.
 */
fun modifyListWithLoops(list1: MutableList<Int>, list2: MutableList<Int>): MutableList<Int> {

    if (list1.size != list2.size) {
        // Remove the first element from the longer list
        if (list1.size > list2.size) {
            list1.removeAt(0)
        } else {
            list2.removeAt(0)
        }
    } else {
        // Append the last element from list2 to list1
        list1.add(list2.last())
    }
    return list1
}

// Example usage of the function
val list1 = mutableListOf(1, 2, 3, 4)
val list2 = mutableListOf(5, 6, 7)
val result = modifyListWithLoops(list1, list2)
/**
 * As a psychologist, you need to create a function that modifies a list by adding or removing elements based on certain conditions.
 *
 * Here's how the function should work:
 *
 * - If the length of list1 is not equal to the length of list2, remove the first element from the longer list.
 *
 * - If the length of list1 is equal to the length of list2, append the last element from list2 to list1.
 *
 * - Finally, return the modified list1.
 *
 * Your task is to complete the code by writing the necessary Kotlin code to solve the exercise.
 */
fun modifyListWithLoops(list1: MutableList<Int>, list2: MutableList<Int>): MutableList<Int> {
/**
 * As a psychologist, you need to create a function that modifies a list by adding or removing elements based on certain conditions.
 *
 * Here's how the function should work:
 *
 * - If the length of list1 is not equal to the length of list2, remove the first element from the longer list.
 *
 * - If the length of list1 is equal to the length of list2, append the last element from list2 to list1.
 *
 * - Finally, return the modified list1.
 *
 * Your task is to complete the code by writing the necessary Kotlin code to solve the exercise.
 */
fun modifyListWithLoops(list1: MutableList<Int>, list2: MutableList<Int>): MutableList<Int> {

    if (list1.size != list2.size) {
        // Remove the first element from the longer list
        if (list1.size > list2.size) {
            list1.removeAt(0)
        } else {
            list2.removeAt(0)
        }
    } else {
        // Append the last element from list2 to list1
        list1.add(list2.last())
    }
    return list1
}

// Example usage of the function
val list1 = mutableListOf(1, 2, 3, 4)
val list2 = mutableListOf(5, 6, 7)
val result = modifyListWithLoops(list1, list2)