/**
 * Exercise:
 * Given a start and stop parameter, create a range and then slice it using the following rules:
 * 1. If the start is negative and the stop is positive, return the slice starting
 *    3 elements from the end and ending 2 elements before the start.
 * 2. If both start and stop are negative, return the slice starting 2 elements from
 *    the end and ending 2 elements before the start.
 * 3. If both start and stop are positive, return the slice starting from index 1
 *    and ending at index -1.
 * 4. If the start is positive and the stop is negative, return the slice starting
 *    from index 2 and ending 1 element before the stop.
 *
 * Note: You can assume that stop is always greater than start.
 */
fun createRangeAndSlice(start: Int, stop: Int): List<Int> {

    val rangeList = (start until stop).toList()

    return when {
        start < 0 && stop > 0 -> rangeList.subList(rangeList.size - 3, start - 2).reversed()
        start < 0 && stop < 0 -> rangeList.subList(rangeList.size - 2, start - 2).reversed()
        start > 0 && stop > 0 -> rangeList.subList(1, rangeList.size - 1)
        else -> rangeList.subList(2, stop - 1)
    }
}
/**
 * Exercise:
 * Given a start and stop parameter, create a range and then slice it using the following rules:
 * 1. If the start is negative and the stop is positive, return the slice starting
 *    3 elements from the end and ending 2 elements before the start.
 * 2. If both start and stop are negative, return the slice starting 2 elements from
 *    the end and ending 2 elements before the start.
 * 3. If both start and stop are positive, return the slice starting from index 1
 *    and ending at index -1.
 * 4. If the start is positive and the stop is negative, return the slice starting
 *    from index 2 and ending 1 element before the stop.
 *
 * Note: You can assume that stop is always greater than start.
 */
fun createRangeAndSlice(start: Int, stop: Int): List<Int> {
/**
 * Exercise:
 * Given a start and stop parameter, create a range and then slice it using the following rules:
 * 1. If the start is negative and the stop is positive, return the slice starting
 *    3 elements from the end and ending 2 elements before the start.
 * 2. If both start and stop are negative, return the slice starting 2 elements from
 *    the end and ending 2 elements before the start.
 * 3. If both start and stop are positive, return the slice starting from index 1
 *    and ending at index -1.
 * 4. If the start is positive and the stop is negative, return the slice starting
 *    from index 2 and ending 1 element before the stop.
 *
 * Note: You can assume that stop is always greater than start.
 */
fun createRangeAndSlice(start: Int, stop: Int): List<Int> {

    val rangeList = (start until stop).toList()

    return when {
        start < 0 && stop > 0 -> rangeList.subList(rangeList.size - 3, start - 2).reversed()
        start < 0 && stop < 0 -> rangeList.subList(rangeList.size - 2, start - 2).reversed()
        start > 0 && stop > 0 -> rangeList.subList(1, rangeList.size - 1)
        else -> rangeList.subList(2, stop - 1)
    }
}