Distance Between Bus Stops

Ok, I cheated on this one by looking at other people’s solution. I initially tried hard to compute the clockwise and counterclockwise sum without realizing that I can actually just compute the clockwise and subtract it from the total sum. Duh! But I reimplemented the idea using Kotlin’s way so give me credit even just for a bit :D

class Solution {
    fun distanceBetweenBusStops(distance: IntArray, start: Int, destination: Int): Int {
        val sum = distance.sum()
        val partial = distance.sliceArray(Math.min(start, destination) until Math.max(start, destination)).sum()
        return Math.min(partial, sum - partial)
    }
}
Runtime: 204 ms, faster than 10.00% of Kotlin online submissions for Distance Between Bus Stops.
Memory Usage: 37.7 MB, less than 100.00% of Kotlin online submissions for Distance Between Bus Stops.