Problem, as an interviewer would state it:
"Implement removeElement(arr, val) — removing every occurrence of val from the array IN PLACE, returning the new, real length, matching the well-known LeetCode-27-style contract."
Examples:
const arr = [3,2,2,3];
removeElement(arr, 3); // returns 2, arr's first 2 elements are now [2,2]
Clarifying questions expected:
- Does the ORDER of the remaining elements need to be preserved, or is any final order of the survivors acceptable?
- Should this genuinely allocate a new array, or must it mutate the original array in place (matching the real LeetCode-27 convention)?
- What is the real, correct meaning of the RETURNED length — is the caller expected to only look at the first
kelements of the mutated array afterward?
Code / implementation expected: Yes — real, direct proof of correct in-place mutation (same array reference, with .length itself updated), returning the correct new length, matching real LeetCode-27 semantics.