Skip to main content
Some of the post didn't make sense. LeetCode may interview but it's providing interview questions. "review" doesn't have a subject. 1146 doesn't make much sense.
Source Link
Emma Marcier
  • 3.7k
  • 3
  • 14
  • 43

I'm posting my C++ code for LeetCode's Snapshot Array. If you have time and would like to review my code, please do so. Thank you!

LeetCode is a platform only for interview questionsinterviewing and competitive programming. On LeetCode, there is a class usually named Solution (for this post is SnapshotArray) with one or more public functions which we are not allowed to rename.

I'm posting my C++ code for LeetCode's Snapshot Array. If you have time and would like to review my code, please do so. Thank you!

LeetCode is a platform only for interview questions and competitive programming. On LeetCode, there is a class usually named Solution (for this post is SnapshotArray) with one or more public functions which we are not allowed to rename.

I'm posting my C++ code for LeetCode's Snapshot Array. If you have time and would like to review, please do so. Thank you!

LeetCode is a platform only for interviewing and competitive programming. On LeetCode, there is a class usually named Solution (for this post is SnapshotArray) with one or more public functions which we are not allowed to rename.

Some of the post didn't make sense. LeetCode may interview but it's providing interview questions. "review" doesn't have a subject. 1146 doesn't make much sense.
Source Link

LeetCode 1146: Snapshot Array

I'm posting my C++ code for LeetCode's Snapshot Array. If you have time and would like to review my code, please do so. Thank you!

LeetCode is a platform only for interviewinginterview questions and competitive programming. On LeetCode, there is an instancea class usually named Solution (for this post is SnapshotArray) with one or more public functions which we are not allowed to rename those.

1146: Snapshot Array

I'm posting my C++ code for LeetCode's Snapshot Array. If you have time and would like to review, please do so. Thank you!

LeetCode is a platform only for interviewing and competitive programming. On LeetCode, there is an instance usually named Solution (for this post is SnapshotArray) with one or more public functions which we are not allowed to rename those.

LeetCode 1146: Snapshot Array

I'm posting my C++ code for LeetCode's Snapshot Array. If you have time and would like to review my code, please do so. Thank you!

LeetCode is a platform only for interview questions and competitive programming. On LeetCode, there is a class usually named Solution (for this post is SnapshotArray) with one or more public functions which we are not allowed to rename.

added 65 characters in body
Source Link
Emma Marcier
  • 3.7k
  • 3
  • 14
  • 43

Probelm

Problem

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 given index to be equal to val. int snap() takes a snapshot of the array and returns the snap_id: the total number of times we called snap() minus 1. int get(index, snap_id) returns the value at the given index, at the time we took the snapshot with the given snap_id

  • 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 given index to be equal to val.
  • int snap() takes a snapshot of the array and returns the snap_id: the total number of times we called snap() minus 1.
  • int get(index, snap_id) returns the value at the given index, at the time we took the snapshot with the given snap_id

Example 1:

Example 1:

Input: ["SnapshotArray","set","snap","set","get"] [[3],[0,5],[],[0,6],[0,0]] Output: [null,null,0,null,5] Explanation: SnapshotArray snapshotArr = new SnapshotArray(3); // set the length to be 3 snapshotArr.set(0,5); // Set array[0] = 5 snapshotArr.snap(); // Take a snapshot, return snap_id = 0 snapshotArr.set(0,6); snapshotArr.get(0,0); // Get the value of array[0] with snap_id = 0, return 5

Constraints:

  • SnapshotArray snapshotArr = new SnapshotArray(3); // set the length to be 3
  • snapshotArr.set(0,5); // Set array[0] = 5
  • snapshotArr.snap(); // Take a snapshot, return snap_id = 0
  • snapshotArr.set(0,6);
  • snapshotArr.get(0,0); // Get the value of array[0] with snap_id = 0, return 5

1 <= length <= 50000 At most 50000 calls will be made to set, snap, and get. 0 <= index < length 0 <= snap_id < (the total number of times we call snap()) 0 <= val <= 10^9

Constraints:

  • 1 <= length <= 50000
  • At most 50000 calls will be made to set, snap, and get.
  • 0 <= index < length
  • 0 <= snap_id < (the total number of times we call snap())
  • 0 <= val <= 10^9

Probelm

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 given index to be equal to val. int snap() takes a snapshot of the array and returns the snap_id: the total number of times we called snap() minus 1. int get(index, snap_id) returns the value at the given index, at the time we took the snapshot with the given snap_id

Example 1:

Input: ["SnapshotArray","set","snap","set","get"] [[3],[0,5],[],[0,6],[0,0]] Output: [null,null,0,null,5] Explanation: SnapshotArray snapshotArr = new SnapshotArray(3); // set the length to be 3 snapshotArr.set(0,5); // Set array[0] = 5 snapshotArr.snap(); // Take a snapshot, return snap_id = 0 snapshotArr.set(0,6); snapshotArr.get(0,0); // Get the value of array[0] with snap_id = 0, return 5

Constraints:

1 <= length <= 50000 At most 50000 calls will be made to set, snap, and get. 0 <= index < length 0 <= snap_id < (the total number of times we call snap()) 0 <= val <= 10^9

Problem

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 given index to be equal to val.
  • int snap() takes a snapshot of the array and returns the snap_id: the total number of times we called snap() minus 1.
  • int get(index, snap_id) returns the value at the given index, at the time we took the snapshot with the given snap_id

Example 1:

Input: ["SnapshotArray","set","snap","set","get"] [[3],[0,5],[],[0,6],[0,0]] Output: [null,null,0,null,5] Explanation:

  • SnapshotArray snapshotArr = new SnapshotArray(3); // set the length to be 3
  • snapshotArr.set(0,5); // Set array[0] = 5
  • snapshotArr.snap(); // Take a snapshot, return snap_id = 0
  • snapshotArr.set(0,6);
  • snapshotArr.get(0,0); // Get the value of array[0] with snap_id = 0, return 5

Constraints:

  • 1 <= length <= 50000
  • At most 50000 calls will be made to set, snap, and get.
  • 0 <= index < length
  • 0 <= snap_id < (the total number of times we call snap())
  • 0 <= val <= 10^9
Post Undeleted by Emma Marcier
Post Deleted by Emma Marcier
Source Link
Emma Marcier
  • 3.7k
  • 3
  • 14
  • 43
Loading