/**
 * Given a list of athletes' speeds, return the rank of each athlete within the specified range.
 *
 * @param athletesList A list of integers representing the speeds of athletes.
 * @param startIndex The start index of the range.
 * @param endIndex The end index of the range.
 * @return A list of integers representing the rank of each athlete within the specified range.
 *
 * Example:
 * getSpeedRank(listOf(9, 5, 7, 3, 8, 2, 1), 1, 4) returns [4, 2, 3, 1]
 */
fun getSpeedRank(athletesList: List<Int>, startIndex: Int, endIndex: Int): List<Int> {

    val sortedAthletes = athletesList.subList(startIndex, endIndex).sorted()
    val rankList = mutableListOf<Int>()
    for (athleteSpeed in athletesList.subList(startIndex, endIndex)) {
        rankList.add(sortedAthletes.indexOf(athleteSpeed) + 1)
    }
    return rankList
}

val athleteSpeeds = listOf(8, 6, 3, 10, 2, 5, 7, 4, 1, 9)
val start = getSpeedRank(athleteSpeeds, 1, 4)
/**
 * Given a list of athletes' speeds, return the rank of each athlete within the specified range.
 *
 * @param athletesList A list of integers representing the speeds of athletes.
 * @param startIndex The start index of the range.
 * @param endIndex The end index of the range.
 * @return A list of integers representing the rank of each athlete within the specified range.
 *
 * Example:
 * getSpeedRank(listOf(9, 5, 7, 3, 8, 2, 1), 1, 4) returns [4, 2, 3, 1]
 */
fun getSpeedRank(athletesList: List<Int>, startIndex: Int, endIndex: Int): List<Int> {
/**
 * Given a list of athletes' speeds, return the rank of each athlete within the specified range.
 *
 * @param athletesList A list of integers representing the speeds of athletes.
 * @param startIndex The start index of the range.
 * @param endIndex The end index of the range.
 * @return A list of integers representing the rank of each athlete within the specified range.
 *
 * Example:
 * getSpeedRank(listOf(9, 5, 7, 3, 8, 2, 1), 1, 4) returns [4, 2, 3, 1]
 */
fun getSpeedRank(athletesList: List<Int>, startIndex: Int, endIndex: Int): List<Int> {

    val sortedAthletes = athletesList.subList(startIndex, endIndex).sorted()
    val rankList = mutableListOf<Int>()
    for (athleteSpeed in athletesList.subList(startIndex, endIndex)) {
        rankList.add(sortedAthletes.indexOf(athleteSpeed) + 1)
    }
    return rankList
}

val athleteSpeeds = listOf(8, 6, 3, 10, 2, 5, 7, 4, 1, 9)
val start = getSpeedRank(athleteSpeeds, 1, 4)