Learner Level
Implement the subsetsCountByBitmask method that returns how many subsets can be formed using bitmasking.
The input is an integer n, representing the number of elements in a set.
Your task is to return how many subsets can be formed from these n elements. A subset may include no elements, some elements, or all elements.
For example, when n = 4, each element has two choices: included or not included. Therefore, the total number of subsets is 2^4 = 16.
Every element has two independent choices: either it is included in a subset or it is not included.
Because there are n elements and each has 2 choices, the total number of subsets is 2^n. This is the same idea used by bitmasking, where every bit represents whether one element is selected.
Calculate 2 multiplied by itself n times and return the result.
Pseudocode:
function subsetsCountByBitmask(n):
count = 1
for i from 1 to n:
count = count * 2
return count