I would understand if the array were provided to you and you had no control over it, but you wrote the code that makes the array… So, modify the code that pushes so that it checks if it needs to push or not, or breaks from the loop before pushing unnecessarily, or whatever.
That was my solution, I couldn’t think of anything else.
I haven’t touched break much in the curriculum here or used it on my own.
I’ll try to see where I can fit break in instead of the IF.
Question, what’s so bad about the IF anyway? is it for speed? and if is how faster is it really?
edit: if (y > num) {break;} I added this inside my while loop instead of the IF, is it better writing the code like this? should you avoid if , if not necessary?