Medium · Linked Lists

Delete every Kth node in DLL

Given the head of a doubly linked list and an integer k, delete every k-th node (positions k, 2k, 3k and so on, counted from the head in the original list), keep every surviving prev and next link consistent, and return the new head; the list is returned unchanged when k ≤ 0 or k exceeds its length.

Examples

Example 1

[1,2,3,4,5,6] k=2

Output: [1, 3, 5]

Example 2

[10,20,30,40,50,60,70] k=3

Output: [10, 20, 40, 50, 70]

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Linked Lists problems