← Back to challenges

Sum of 1-N Succession

JavaScriptHardmathnumberslogic

Instructions

In this challenge you must create a program which takes a number n and returns the length or number of digits in all numbers from 1 to n concatenated.

Examples

concatenationSum(5) ➞ 5

concatenationSum(10) ➞ 11

concatenationSum(13) ➞ 17

Notes

Keep in mind that the output is the number of digits in the concatenated number. For example, if the input was 5, the output would be 5 because 12345 has 5 digits. Similarly when the input is 13 the ouput is 17 because 12345678910111213 has 17 digits.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.