Time complexity : 31 times O(N) |  2 ms Beats 100.00%
Intuition\n for value = 7 \n we can find a number such that :  num | (num + 1) = value\nby setting any one bit of value\'s binary representation from 1 to 0.\nT
# Intuition\n for value = 7 \n we can find a number such that :  num | (num + 1) = value\nby setting any one bit of value\'s binary representation from 1 to 0.\nTo find the minimum, start from 31st bit and which ever number we get after turning any one bit from 1 to 0, does prove our given condition is the answer\nHence for any number we just need at max 31 comparision to find desired value.\n\n![image.png](https://assets.leetcode.com/users/images/4eee94e9-749d-48b2-aa08-ddc7978d7ac3_1728828521.216453.png)\n\n\n\n# Code\n```java []\nclass Solution {\n    public int[] minBitwiseArray(List<Integer> nums) {\n        int[] ans = new int[nums.size()];\n        int i = 0;\n        for (int num : nums) {\n            ans[i++] = getMinValue(num);\n        }\n        return ans;\n    }\n\n    private int getMinValue(int num) {\n        int ans = -1;\n        for (int i = 31; i >= 0; i--) {\n            if (((num >> i) & 1) == 1) {\n                // this bit is 1, now change this bit to 0 and check if update number is valid or not\n                int temp = (1 << i) ^ num;\n                if (isValid(temp, num)) {\n                    return temp;\n                }\n            }\n        }\n        return ans;\n    }\n\n    private boolean isValid(int temp, int num) {\n        return (temp | (temp + 1)) == num;\n    }\n}\n```
['Math', 'Bit Manipulation', 'Java']