For every bit maintain a dp array dp[i],(for different bits) for dp[i]=1+min(dp[i-1],dp[i-1]); and for dp[i]=1+min(dp[i-2],dp[i-2]) if swapping conditions are satisfying else
dp[i]=dp[i] (for same bits) copy from previous values,
Answer will be min(dp[n-1],dp[n-1])
thank you so much for helping me … i have done using this way already .(greedy way) …
i was asking if i do not apply this logic (greedy) and go on solving all the possible cases and finding out the minimum using dp approach in given time complexity ??