[Kotlin] One pass, O(n), 100% 🎉🎉🎉 
IntuitionIterating over x in nums, if we remember the first and last time we saw x, we can always calculate the distant of the current x to the last x and the f
# Intuition
Iterating over `x` in `nums`, if we remember the first and last time we saw `x`, we can always calculate the distant of the current `x` to the last `x` and the first `x`.
If we update correctly along the way, we will end up with a complete "minimum distance map" for *all* indices in nums.

# Approach
Maintain two integer arrays `first` and `last` that keep track of the corresponding indices for each possible `x` in `nums`.
For each index `i` in nums, do the proper bookkeeping for the distances  for `i` and `i - 1` and `first[x]`.

The result is then the subsequence of `all` that corresponds to the indices in `queries`.

# Complexity
- Time complexity:
O(`|nums|`)

- Space complexity:
O(`|max(nums) - min(nums)|`), where min/max are taken from the problem description

# Code
```kotlin []
class Solution {
    fun solveQueries(nums: IntArray, queries: IntArray): List<Int> {
        val first = IntArray(1000001) { -1 }
        val last = IntArray(1000001) { -1 }

        val all = IntArray(nums.size) { nums.size }
        for ((i, x) in nums.withIndex()) {
            if (first[x] == -1) {
                first[x] = i
                last[x] = i
            } else {
                all[i] = i - last[x]
                if (all[i] < all[last[x]]) all[last[x]] = all[i]
                val d = nums.size - i + first[x]
                if (d < all[i]) all[i] = d
                if (d < all[first[x]]) all[first[x]] = d
                last[x] = i
            }
        }

        return queries.map { if (all[it] == nums.size) -1 else all[it] }
    }
}
```
['Kotlin']