Easy Solution with Explanation | c++
let\'s take an example \nn = 3\n\nIntially ans = 1;\n\n\nfor i --> 2\n\tnumber of bits in 2 is 2;\n\tshift answer by number of bits i.e. 2 ans add i\n\tans = 1 
let\'s take an example \n**n = 3**\n\n**Intially ans = 1;**\n\n\n**for i --> 2**\n\tnumber of bits in 2 is 2;\n\tshift answer by number of bits i.e. 2 ans add i\n\tans = 1 << 2 + 2\n\t\t= 6\n\n**for i --> 3**\n\tnumber of bits in 3 is 2;\n\tshift answer by number of bits i.e. 2 ans add i\n\tans = 6 << 2 + 3\n\t\t= 27\n\n**so, answer is 27.**\n```\nclass Solution {\npublic:\n    int concatenatedBinary(int n) {\n        long long ans = 1;\n        int mod = 1e9 + 7;\n        for(int i = 2; i <= n; i++) {\n            int bits = (int)log2(i)+1;  // count number of bits in i\n            ans = ((ans << bits) % mod + i) % mod; // left shift current ans by number of bits in i and current element to ans.\n        }\n        return (int)ans;\n    }\n};\n```
[]