Snapshot Array
Implement a SnapshotArray that supports the following interface:
SnapshotArray(int length)
initializes an array-like data structure with the given length. Initially, each element equals 0.void set(index, val)
sets the element at the givenindex
to be equal toval
.int snap()
takes a snapshot of the array and returns thesnap_id
: the total number of times we calledsnap()
minus1
.int get(index, snap_id)
returns the value at the givenindex
, at the time we took the snapshot with the givensnap_id
Example 1:
Constraints:
1 <= length <= 50000
At most
50000
calls will be made toset
,snap
, andget
.0 <= index < length
0 <= snap_id <
(the total number of times we callsnap()
)0 <= val <= 10^9
PreviousFind Two Non-overlapping Sub-arrays Each With Target SumNextCount pairs in array whose sum is divisible by K
Last updated