Simple Array Approach  | Beats 100% in Time and Space
\n### Simple Array Approach  | Beats 100% in Time and Space | Beginner Friendly & Easy to Understand\n\n\nclass Solution {\n    public int minChanges(int n, int
![image](https://assets.leetcode.com/users/images/e34525b5-471e-4314-b1b5-e682b5e69f7c_1721564648.829948.png)\n### Simple Array Approach  | Beats 100% in Time and Space | Beginner Friendly & Easy to Understand\n\n```\nclass Solution {\n    public int minChanges(int n, int k) {        \n\t//If n cannot be converted into k\n        if ( (n & k) != k){\n            return -1;\n        }\n        int res = 0;\n\t\t//Convert values into char array\n        char[] nA= Integer.toBinaryString(n).toCharArray();\n        char[] kA= Integer.toBinaryString(k).toCharArray();\n\t\t\n        int nl = nA.length-1;\n        int kl = kA.length-1;\n\t\t\n\t\t//Condition covering scenarios where nA and kA both have value in char array\n        while(nl>=0 && kl>=0){\n            if(nA[nl]!=kA[kl]){\n                res++;\n            }\n            nl--;\n            kl--;\n        }\n\t\t//Condition when k array is exhauted, but n has some elements left\n        while(nl>=0){\n            if(nA[nl]==\'1\'){\n                res++;\n            }\n            nl--;\n        }\n        return res;\n    }\n}\n\n```
['Array', 'Java']