-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Description
Bug Report for https://neetcode.io/problems/dynamicArray
The sample solution implements:
# Remove the last element in the array
def popback(self) -> int:
if self.length > 0:
# soft delete the last element
self.length -= 1
# return the popped element
return self.arr[self.length]
However, this is wrong. The element is not removed and can still be accessed by get
. Thus, there should (a) be a test case that covers this to ensure that the implementation matches the requirements, and (b) the Python
sample solution should use pop
(or, at least, set the element to 0). The sample solutions can look something like:
def popback(self) -> int:
if self._length > 0:
self._length -= 1
return self._array.pop(self._length)
Metadata
Metadata
Assignees
Labels
No labels