Question DSA-BIT-0075
HardHow do you iterate over all submasks of a mask m efficiently?
- A.
s = m; while s: process(s); s = (s − 1) & m
- B.
s = m >> 1 repeatedly
- C.
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Bit Manipulation question
How do you iterate over all submasks of a mask m efficiently?
s = m; while s: process(s); s = (s − 1) & m
s = m >> 1 repeatedly
Sign up free to see the answer and a step-by-step explanation.
s = m ^ 1 repeatedly
for s in range(m)