What would be the time complexity for the following code? Is it O(n^2)? Because for loop is O(n), inside the for loop there is splice(), and splice() is O(n) as well. So the time complexity will be O(n^2)? Please correct me if I’m wrong. Thanks!
Here is the code snippet:
function removeEven(arr) {
for (let i = 0; i < arr.length; i++) {
if (arr[i] % 2 === 0) {
arr.splice(i, i);
i--;
}
}
return arr;
}