Beats 100%| Beginner Friendly | Easy Approach | Basic 🍟🧨
Approach\n1)we find the binary representations of n and k.\n2)Any bit that is equal to 1 in n and equal to 0 in k needs to be changed.\n3)if there is a bit that
# Approach\n1)we find the binary representations of n and k.\n2)Any bit that is equal to 1 in n and equal to 0 in k needs to be changed.\n3)if there is a bit that is equal to 0 in n and equal to 1 in k --> return -1\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n# Python3\n\n```\nclass Solution:\n    def minChanges(self, n: int, k: int) -> int:\n        if n==k:\n            return 0\n        nb=bin(n)[2:]\n        kb=bin(k)[2:]\n        if(len(nb)<len(kb)):\n            diff=len(kb)-len(nb)\n            nb=\'0\'*diff+nb\n        if(len(kb)<len(nb)):\n            diff=len(nb)-len(kb)\n            kb=\'0\'*diff+kb\n        count=0\n        for i in range(len(nb)):\n            if nb[i]==\'1\' and kb[i]==\'0\':\n                count+=1\n            if nb[i]==\'0\' and kb[i]==\'1\':\n                return -1\n        return count\n```\n# Java\n```\nclass Solution {\n    public int minChanges(int n, int k) {\n        String nb = Integer.toBinaryString(n);\n        String kb = Integer.toBinaryString(k);\n        if(n==k) return 0;\n         int len1 = nb.length();\n         int len2 = kb.length();\n        if (len1 > len2) {\n            kb = padWithZeros(kb, len1 - len2);\n        } else if (len2 > len1) {\n            nb = padWithZeros(nb, len2 - len1);\n        }\n        int count=0;\n        for(int i=0;i<nb.length();i++){\n            if(nb.charAt(i)==\'1\' && kb.charAt(i)==\'0\'){\n                count++;\n            }\n            if(nb.charAt(i)==\'0\' && kb.charAt(i)==\'1\'){\n                return -1;\n            }\n        }\n        return count;\n    }\n        private String padWithZeros(String binary, int zerosToAdd) {\n        StringBuilder sb = new StringBuilder();\n        for (int i = 0; i < zerosToAdd; i++) {\n            sb.append(\'0\');\n        }\n        sb.append(binary);\n        return sb.toString();\n    }\n}\n```
['Java', 'Python3']