Company: Tally_24july
Difficulty: medium
Resolving to Zero Problem You are given a binary character array s of length n . The array represents a non-negative integer x , with s[0] as the most significant bit and s[n-1] as the least significant bit: x = (s[n-1] - '0') * 2^0 + (s[n-2] - '0') * 2^1 + ... + (s[0] - '0') * 2^(n-1) Let setBits(x) be the number of 1 bits in the binary representation of x . Define f(x) as the number of times the following operation must be applied to x until x becomes 0 : x = x % setBits(x) where % is the modulo operator. This process always reaches 0 after a finite number of operations. For each i from 1 to n , let s_i be the value obtained from s by flipping its i -th bit, that is, changing s[i-1] from '0' to '1' or from '1' to '0' (bit 1 is the most significant bit s[0] ). Each flip is applied to the original array independently; flips do not accumulate. Complete the function resolvedArray , which receives the array s and returns an array of n integers whose i -th element is f(s_i) . If a flip tur