C# List of Dictionaries
Approach\n- Using List<Dictionary<int, int>> to store snapId and value.\n- When getting value, if the snapId in not in the dictionary go back to previuous snaps
# Approach\n- Using `List<Dictionary<int, int>>` to store `snapId` and value.\n- When getting value, if the `snapId` in not in the dictionary go back to previuous snapshot\n\n# Code\n```\npublic class SnapshotArray\n{\n    private readonly List<Dictionary<int, int>> _array;\n    private int _snapshotId;\n\n    public SnapshotArray(int length)\n    {\n        _array = new List<Dictionary<int, int>>(length);\n        for (var i = 0; i < length; i++)\n        {\n            _array.Add(new Dictionary<int, int> {[0] = 0});\n        }\n    }\n\n    public void Set(int index, int val)\n    {\n        _array[index][_snapshotId] = val;\n    }\n\n    public int Snap()\n    {\n        return _snapshotId++;\n    }\n\n    public int Get(int index, int snapId)\n    {\n        var dictionary = _array[index];\n        \n        // If snapId is not in the dictionary we should go back to previous snapshot\n        while (!dictionary.ContainsKey(snapId))\n        {\n            --snapId;\n        }\n\n        return dictionary[snapId];\n    }\n}\n\n```
['C#']