Very simple Java solution with explanation
Here is the process how you can derive recurrent formula\n\nresult(n) = result(n - 1) * 2^binaryDigitsOf(n) + n\n\nwhere binaryDigitsOf(n) is the number of bina
Here is the process how you can derive recurrent formula\n\nresult(n) = result(n - 1) * 2^binaryDigitsOf(n) + n\n\nwhere binaryDigitsOf(n) is the number of binary digits needed to write number n. \n\ni = 1:\n1 -> "1" = 1\nresult is 1\n\ni = 2:\n2 -> "1""10" = (110) = (1 10) = 1 * 4 + 2 = result * 2^binaryDigitsOf(2) + 2 = result * 2^binaryDigitsOf(i) + i = 6\nresult is 6\n\ni = 3:\n3 -> "110""11" = (11011) = (110 11) = 6 * 4 + 3 = result * 2^binaryDigitsOf(3) + 3 = result * 2^binaryDigitsOf(i) + i = 27\nresult is 27\n\ni = 4:\n4 -> "11011""100" = (11011100)  = (11011 100) = 27 * 8 + 4 = result * 2^binaryDigitsOf(4) + 4 = result * 2^binaryDigitsOf(i) + i = 220\nresult is 220\n\nAnd so on until n. We just need to take care of overflow, because of that we use long instead of int and do modulo operation. At the end we convert it to the int. That\'s it. Enjoy in code!\n\n```\nclass Solution {\n    public int concatenatedBinary(int n) {\n        \n\t\tint MOD = 1_000_000_007;\n\t\t\n\t\tlong[] powersOf2 = getPowersOf2();\n\t\t\n\t\tlong result = 0;\n\t\t\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tresult = (result * powersOf2[getNumberOfBinaryDigits(i, powersOf2)] + i) % MOD;\n\t\t}\n\t\t\n\t\treturn (int) (result % MOD);\n    }\n\t\n\tprivate int getNumberOfBinaryDigits(int n, long[] powersOf2) {\n\t\t\n\t\tfor (int i = 1; i < 32; i++) {\n\t\t\tif (powersOf2[i] > n) {\n\t\t\t\treturn i;\n\t\t\t} else if (powersOf2[i] == n) {\n\t\t\t\treturn i + 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn 1000; // never will come here\n\t}\n\n\tprivate long[] getPowersOf2() {\n\t\tlong[] powersOf2 = new long[32];\n\t\t\n\t\tpowersOf2[0] = 1;\n\t\t\n\t\tfor (int i = 1; i < 32; i++) {\n\t\t\tpowersOf2[i] = 2 * powersOf2[i - 1];\n\t\t}\n\t\t\n\t\treturn powersOf2;\n\t}\n}\n```
[]