'What is the time complexity of setting a new vector equal to an existing vector?

Let's say we have a vector<int> nums, and we want to keep track of its original state, so we create a vector<int> original and set that equal to nums as follows:

vector<int>original = nums; 

Would the time complexity of this be O(N) or O(1)?



Solution 1:[1]

Every value in the first vector vector<int> nums, must be individually copied into the second vector vector<int> original. So the time-complexity would be O(n).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Priya Thiagarajan