Adjacent flag configurations
A rollout tool stores n feature flags as a row of bits, one per flag, each on (1) or off (0). To limit blast radius, policy forbids enabling two adjacent flags at the same time. Return how many distinct flag configurations of length n satisfy the policy. For n = 0 return 1 (the empty configuration). For example, n = 2 allows 00, 01, and 10 — but not 11 — so the answer is 3.
Implement
count_valid_flag_masks(n: int) → intExamples
in
[2]out3in
[3]out5What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 12 min
solution.py
InputExpectedGot
[2]3not run yetsample[3]5not run yetsample