Consider the statement :
string bitmask = bitset<32>(i).to_string().substr(32 - n);
n is the size of a vector.
What should be the space complexity for this ?
My take is that it should be O(logN)
.
Most places I see say the space complexity for this should be O(N).
According to me if we do not include the space used in buffer the space complexity for this doesn’t exceed O(logN)`.
Am i correct or am I missing something?
I am trying to determine the space complexity for this code :
class Solution {
public:
vector<vector<int>> subsets(vector<int>& nums) {
int n = nums.size();
vector<vector<int>> output;
for (int i = pow(2, n); i < pow(2, n + 1); ++i) {
// generate bitmask, from 0..00 to 1..11
string bitmask = bitset<32>(i).to_string().substr(32 - n);
// append subset corresponding to that bitmask
vector<int> curr;
for (int j = 0; j < n; ++j) {
if (bitmask.at(j) == '1') curr.push_back(nums[j]);
}
output.push_back(curr);
}
return output;
}
};
The answers say its O(N)