using System.Collections.Generic;
private SortedDictionary<int, Dictionary<string, string>> timeMap;
timeMap = new SortedDictionary<int, Dictionary<string, string>>();
public void Set(string key, string value, int timestamp) {
if (!timeMap.TryGetValue(timestamp, out var values))
values = new Dictionary<string, string>();
timeMap.Add(timestamp, values);
public string Get(string key, int timestamp) {
foreach (var kvp in timeMap.Reverse())
if (kvp.Key <= timestamp && kvp.Value.TryGetValue(key, out var value))
public static void Main()
TimeMap timeMap = new TimeMap();
timeMap.Set("key1", "value1", 1);
timeMap.Set("key2", "value2", 2);
Console.WriteLine(timeMap.Get("key1", 0));
Console.WriteLine(timeMap.Get("key1", 1));
Console.WriteLine(timeMap.Get("key2", 2));
Console.WriteLine("Hello World");