/**
 * Concatenate all the strings in the given list and return a new string that is a slice of
 * the concatenated string based on the given indices.
 *
 * @param strings List of strings to be concatenated.
 * @param indices List of indices indicating the slice of the concatenated string.
 * @return Slice of the concatenated string based on the given indices.
 * @throws IndexOutOfBoundsException If any index provided in the indices list is out of range.
 */
fun concatenateStringsAndSliceList(strings: List<String>, indices: List<Int>): String {

    val concatenatedString = strings.joinToString("")

    var result = ""
    for (index in indices) {
        if (index >= concatenatedString.length) {
            throw IndexOutOfBoundsException("Index out of range.")
        }
        result += concatenatedString[index]
    }

    return result
}
/**
 * Concatenate all the strings in the given list and return a new string that is a slice of
 * the concatenated string based on the given indices.
 *
 * @param strings List of strings to be concatenated.
 * @param indices List of indices indicating the slice of the concatenated string.
 * @return Slice of the concatenated string based on the given indices.
 * @throws IndexOutOfBoundsException If any index provided in the indices list is out of range.
 */
fun concatenateStringsAndSliceList(strings: List<String>, indices: List<Int>): String {
/**
 * Concatenate all the strings in the given list and return a new string that is a slice of
 * the concatenated string based on the given indices.
 *
 * @param strings List of strings to be concatenated.
 * @param indices List of indices indicating the slice of the concatenated string.
 * @return Slice of the concatenated string based on the given indices.
 * @throws IndexOutOfBoundsException If any index provided in the indices list is out of range.
 */
fun concatenateStringsAndSliceList(strings: List<String>, indices: List<Int>): String {

    val concatenatedString = strings.joinToString("")

    var result = ""
    for (index in indices) {
        if (index >= concatenatedString.length) {
            throw IndexOutOfBoundsException("Index out of range.")
        }
        result += concatenatedString[index]
    }

    return result
}