Solved. I should've used the given parameter numsSize for the loops. Now it works. Thanks to @John3136