Size the simulation first
transcript
The contest statement says what to do. Print every number up to n. Easy. Or is it?
Now read the limit. n can be ten to the twelve. A judge runs ten to the eight steps a second.
That is ten thousand seconds. The limit is one or two seconds. Time limit exceeded, guaranteed. So find the work that repeats.
Numbers come in blocks of equal width. One to nine: nine digits. Ten to ninety-nine: a hundred and eighty. The last block is cut short.
Up to a hundred and twenty, that is two fifty-two. Up to ten to the twelve: thirteen blocks. Thirteen steps instead of a trillion.
Same work per item? Find a formula. Same work per block? One product. Many ranges? Prefix counts.
Size the process from the limits. Do it before you write code. Far above ten to the eight, count it. Full breakdown in the lecture.