Remove Element
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an integer array nums and an integer val. Remove every occurrence of val and keep the remaining elements in the same relative order they had in nums.
Return the compacted array: the elements of nums that are not equal to val, in their original order. If every element equals val (or nums is empty), return [].
In a real interview this is posed as an in-place compaction using O(1) extra space: write the kept elements into the front of nums with a write pointer, then return that prefix.
Examples
Constraints
- 0 <= nums.length <= 100
- 0 <= nums[i] <= 50
- 0 <= val <= 100
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.