/**
 * This function takes a list of expenses and a limit, and calculates the total expenses
 * without exceeding the limit. If the total expenses exceeds the limit, it will return the
 * sum of expenses until the limit is reached, otherwise it will return the total expenses.
 */
fun calculateTotalExpenses(expenses: List<Int>, limit: Int): Int {

    var totalExpenses = 0
    var i = 0

    while (i < expenses.size && totalExpenses + expenses[i] <= limit) {
        totalExpenses += expenses[i]
        i++
    }

    return totalExpenses
}
/**
 * This function takes a list of expenses and a limit, and calculates the total expenses
 * without exceeding the limit. If the total expenses exceeds the limit, it will return the
 * sum of expenses until the limit is reached, otherwise it will return the total expenses.
 */
fun calculateTotalExpenses(expenses: List<Int>, limit: Int): Int {
/**
 * This function takes a list of expenses and a limit, and calculates the total expenses
 * without exceeding the limit. If the total expenses exceeds the limit, it will return the
 * sum of expenses until the limit is reached, otherwise it will return the total expenses.
 */
fun calculateTotalExpenses(expenses: List<Int>, limit: Int): Int {

    var totalExpenses = 0
    var i = 0

    while (i < expenses.size && totalExpenses + expenses[i] <= limit) {
        totalExpenses += expenses[i]
        i++
    }

    return totalExpenses
}