Delete N Nodes After M Nodes of a Linked List
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 the head of a linked list and two positive integers m and n. Starting at the head, repeat the following until the list ends: keep the next m nodes, then delete the n nodes after them.
If fewer than m nodes remain, keep them all. If fewer than n nodes remain to delete, delete them all. Return the head of the modified list.
Examples
Constraints
- 1 <= number of nodes <= 10^4
- 1 <= Node.val <= 10^6
- 1 <= m, n <= 1000
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.