Here’s a Python code snippet that outlines my method using a dictionary along with two variables, lastSetAll and timeStamp . class DataStructure : def __init__ ( self ) : self . data = { } self . lastSetAll = 0 self . timeStamp = 0 def get ( self , index ) : if index not in self . data or self . data [ index ] [ 1 ] < self . timeStamp : return self . lastSetAll else : return self . data [ index ] [ 0 ] def setall ( self , value ) : self . lastSetAll = value self . timeStamp += 1 In the get() method, we verify whether the index is absent from the dictionary or if the setAll operation occurred after the value was set at that index. If either condition is met, we return the lastSetAll value, which represents the most recent valid value for that index; otherwise, we return the actual value. For the setall() method, we simply update the lastSetAll and timeStamp , ensuring that this operation runs in constant time.