Code Room
CodingMediumcod-g1487
Subject Dynamic programming 1dLevel Entry–Mid~12 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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) → int
Examples
in[2]out3
in[3]out5
What 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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.