Bidgely SDE OA question.

Given a binary string of length 2*N ,you can apply N operations and in an operation you can choose any two indices (i , j ). Invert the bits in between i and j (inclusive). Find the number of ways of setting all the bits to 1.Each pair of index can be selected at most once.
eg . N = 2 , s = 0110 (ans = 4)
We could select indices 0 and 3 and apply the given operation to get 1001,then choose indices 1,2 to get 1111 in two operations exactly. Similarly we could first choose the indices 0 and 2 to get 1000 then choose indices 1 and 3 to get 1111 in two operations...in this way there are a total of 4 operations to set all bits in N moves.
N = 5 , s = 1111111111 ( ans = 5!)

Comments (0)