Is the question in #12 well defined?
In an edge case of calling mystery(n) and n is greater than all the elements in the numbers array, the call returns 0 and set m at 0. This would make Option E invalid, right?
Option E: All values in position 0
to m-1
are less than or equal to num
.
Hi Bonnie,
If I’m reading your thoughts right, for a concrete example of what you are describing:
A call to mystery(10) and 10 is greater than all the elements in the array, let’s say it contains [1,2,3,4,5].
If n is greater than all the elements in the numbers array, numbers[k] (the current element)will never be greater than num(the parameter which holds n), so k will not be returned.
The loop will finish, and the length of the array will be returned, which in my example is 5. letter E, that all values from 0 to m-1, which is indices 0 to 4 in this case, will be less than or equal to num, 10.
In your question you said the call would return a 0, which would only happen if the first element in the array is larger than the parameter.
I hope this helps!
Best,
Lindsay
Hi Lindsay,
Thank you for the prompt response and the detailed explanation! I understood the case you described. However, I had a typo in my first post from this afternoon. I meant to say if n is less than all the elements in the numbers array, for example, n is 0, and the int numbers = [1, 2, 3, 4, 5], then mystery(0) returns 0, which set m at 0. This would make Option E invalid, right?
Hi Bonnie,
With what you described, answer E is definitely a bit awkward- if m is set at 0 then answer E would be describing positions from 0 to -1. Since index -1 doesn’t exist for an array, one could make the argument that this would indicate that there are no values less than or equal to the parameter num . But, I agree that this question could use some clarifying.
Thank you,
Lindsay