Toggle feature flag bit
Your task
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).
Examples
toggle_flag(state: int, k: int) -> intExample 1
Input
toggle_flag(5, 1)Output
7Example 2
Input
toggle_flag(7, 0)Output
6