As I can see, you have written all the needed logic for a solution in O(1), but without node.js you need to assemble a line first, before printing it entirely. Something like this was my intention for allowing O(n).
Of course, your program consumes linear space, but I think the core concept can be regarded, like Alexey's, as O(1) solution.
I agree to your comment about ranges, by the way. Would you like to submit Python code?
As I can see, you have written all the needed logic for a solution in O(1), but without node.js you need to assemble a line first, before printing it entirely. Something like this was my intention for allowing O(n).
Of course, your program consumes linear space, but I think the core concept can be regarded, like Alexey's, as O(1) solution.
I agree to your comment about ranges, by the way. Would you like to submit Python code?
I'd like to, but it's been a while since I last used Python and I've forgotten most of the rest of the nice syntax features.