Block sequence Time : Space : 12345678910111213141516171819202122int solve(long long n){ for(long long i = 1, sum = 1, add = 1, po = 10; n > sum;) { n -= sum; i += 1; if(i == po) { add += 1; po *= 10; } sum += add; } for(long long i = 1, add = 1, po = 10;;) { if(n > add) n -= add; else { return std::to_string(i)[n-1] - '0'; } i += 1; if(i == po) { add += 1, po *= 10; } } return -1;}