Ohhhh you only printed the final screen LOL!
Since these are interview type questions, those are my interview type answers. It tells them a bit about me, and helps me learn a bit about them.
A boss who looks over that and says, “You didn’t print results from 1 to 10 ^ 7”, without asking me WHY, is one I don’t want to work for. They’re not into creative solutions, original thinking, or individual problem solving — they just want a monkey that can code up to perfect specifications. It’s too high stress of a job for me, so, “NO THANKS!”
Now, if he asks why I chose such an approach, I can tell him:
“Our view port is limited by printing to the monitor, so there’s no reason to just run and scroll the screen excessively. Instead, I printed a whole screen of results, stored the solutions in an array, improved execution times, and now have access to any portion of that data that you’d like to view and work with, on hand.”
I not only completed his task, but I *improved* upon it.
Which in some companies will get you promoted. In others, it’ll get you fired.
Luckily for me, I don’t want to work for those second BLEEPERS!