You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
Memory usage needs to be more efficient. In this code snippet, too many unused 0 element were stored in the dictionary value. Instead, only store used index and value. A nested dictionary does the trick
This code snippet still duplicates previous snap_array, thus create redundency in elements. for example:
Instead of making a copy to all elements, we only need to make new copies of the elements that has been modified.
For the remaining unchanged elements, we can query them by a backward while loop, which increase the time complexity back to O(N)
Activity
tech-cow commentedon Mar 20, 2020
1146. Snapshot Array
Brute Force | Memory Limit Exceeded
Memory usage needs to be more efficient. In this code snippet, too many unused
0
element were stored in the dictionary value. Instead, only store used index and value. A nested dictionary does the trickHashmap + Deepcopy
This code snippet still duplicates previous

snap_array
, thus create redundency in elements. for example:Instead of making a copy to all elements, we only need to make new copies of the elements that has been modified.
For the remaining unchanged elements, we can query them by a backward while loop, which increase the time complexity back to O(N)
However the time complexity is GREAT
set() O(1)
set() O(1)
get() O(1)
Backward While Loop
We can make this search faster by replacing linear query with a binary search
Backward Binary Search
Code Snippet from @lee215