Code RoomToggle feature flag bit
EasyPrep Room Coding #706

Toggle feature flag bit

CodingAlgorithms & data structuresEntry–Mid~10 min

A feature-flag service stores a rollout state as a non-negative integer, one flag per bit. An admin clicks a switch in the UI, which must flip flag k: if bit k is 0 it becomes 1, and if it is 1 it becomes 0, leaving every other bit untouched. Given the current state (0 <= state < 2^31) and the flag index k (0 <= k <= 30), return the new state. For example, state 5 (binary 101) with k = 1 returns 7 (binary 111).

Implement
toggle_flag(state: int, k: int) → int
Examples
in[5,1]out7
in[7,0]out6
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.

0:00 of about 10 min
InputExpectedGot
[5,1]7not run yetsample
[7,0]6not run yetsample