/**
 * A geologist has collected rock samples and labeled them with unique numbers.
 * However, due to a mistake, the labels have been split into two separate strings.
 * Your task is to concatenate the strings back together by specifying the indices of the characters
 * to include in the final label string.
 *
 * @param word1 The first part of the label string.
 * @param word2 The second part of the label string.
 * @param index1 The starting index for the characters to include from word1.
 * @param index2 The starting index for the characters to include from word2.
 * @return The concatenated label string.
 *
 * Example:
 * joinWords("rock", "sample", 2, 3) -> "rastle"
 * joinWords("igneous", "sedimentary", 4, 7) -> "ousme"
 */
fun joinWords(word1: String, word2: String, index1: Int, index2: Int): String {

    if (index1 < 0 || index2 < 0) {
        return "Invalid index! Index must be a positive integer."
    }

    if (index1 >= word1.length || index2 >= word2.length) {
        return "Invalid index! Index out of bounds."
    }

    return word1.substring(index1) + word2.substring(index2)
}
/**
 * A geologist has collected rock samples and labeled them with unique numbers.
 * However, due to a mistake, the labels have been split into two separate strings.
 * Your task is to concatenate the strings back together by specifying the indices of the characters
 * to include in the final label string.
 *
 * @param word1 The first part of the label string.
 * @param word2 The second part of the label string.
 * @param index1 The starting index for the characters to include from word1.
 * @param index2 The starting index for the characters to include from word2.
 * @return The concatenated label string.
 *
 * Example:
 * joinWords("rock", "sample", 2, 3) -> "rastle"
 * joinWords("igneous", "sedimentary", 4, 7) -> "ousme"
 */
fun joinWords(word1: String, word2: String, index1: Int, index2: Int): String {
/**
 * A geologist has collected rock samples and labeled them with unique numbers.
 * However, due to a mistake, the labels have been split into two separate strings.
 * Your task is to concatenate the strings back together by specifying the indices of the characters
 * to include in the final label string.
 *
 * @param word1 The first part of the label string.
 * @param word2 The second part of the label string.
 * @param index1 The starting index for the characters to include from word1.
 * @param index2 The starting index for the characters to include from word2.
 * @return The concatenated label string.
 *
 * Example:
 * joinWords("rock", "sample", 2, 3) -> "rastle"
 * joinWords("igneous", "sedimentary", 4, 7) -> "ousme"
 */
fun joinWords(word1: String, word2: String, index1: Int, index2: Int): String {

    if (index1 < 0 || index2 < 0) {
        return "Invalid index! Index must be a positive integer."
    }

    if (index1 >= word1.length || index2 >= word2.length) {
        return "Invalid index! Index out of bounds."
    }

    return word1.substring(index1) + word2.substring(index2)
}