Memory Exceeded


#1

Getting MLE using only two variables i and j,declared on two separate lines as well
Any help?


#2

you also need to keep only required element in vector A, this means you will have to resize vector A.


#3

But the task description says: “It does not matter what is left beyond the expected length.”. It should be modified to meet the requirements of the solution checker.


#4

declare variable outside the for loop. do not use local variable…


#5

Yeah agreed, But what @tanya-anand said works, so just suggest an edit saying that the solution error must meet the requirements of the question.


#6

For C++ two pointers approach is giving MLE and the same logic in python is accepted. Try to submit in Python or some other language.

class Solution:
# @param A : list of integers
# @param B : integer
# @return an integer
def removeElement(self, A, B):
i = 0
j = 0
while(i<len(A)):
if(A[i]==B):
i+=1
continue
else:
A[j] = A[i]
j+=1
i+=1
return j


#7

If working in C++, make sure to call resize() before returning the result. This way your solution will pass the MLE.