Kotlin simple TreeMap solution
\nimport java.util.*\n\nclass SnapshotArray(length: Int) {\n\n    private val snaps = Array(length) { TreeMap<Int, Int>() }\n    private var snapId: Int = 0\n\n
```\nimport java.util.*\n\nclass SnapshotArray(length: Int) {\n\n    private val snaps = Array(length) { TreeMap<Int, Int>() }\n    private var snapId: Int = 0\n\n    fun set(index: Int, value: Int) {\n        snaps[index][snapId] = value\n    }\n\n    fun snap(): Int {\n        return snapId++\n    }\n\n    fun get(index: Int, snap_id: Int): Int {\n        val versions = snaps[index]\n        return versions.floorEntry(snap_id)?.value ?: 0\n    }\n\n}\n```
[]