-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Hey, I just found out about the site so maybe I'm missing something but I came across this "problem" on the first dynamic array challenge: https://neetcode.io/problems/dynamicArray
Consider the following test case:
["Array", 2, "pushback", 0, "pushback", 1, "pushback", 2, "getSize", "getCapacity"]
The expected result is:
[null,null,null,null,3,4]
At first, I didn't quite understand the reason behind the "4" but after looking at the solution I assume that the result is expecting the "pushback" function to implement "resize" despite this not being mentioned anywhere in the description.
However, if you implement the pushback function with a "+1" capacity change instead of doubling it, then the final capacity is going to be 3, which fails the test. In my opinion, that's still a valid solution because it's impossible to know you're supposed to double the capacity and you only really need 3 positions.
My suggestion is to either add a clause saying that "if the array is full then double the capacity (or call resize())" which would be the easy solution, or rewrite the test cases to not expect any kind of specific implementation of the "pushback" function but that might much bigger job.
Please let me know if I missed something,
Thank you!