375. Skip M Delete N Nodes

MediumLinked ListLinked ListSimulation

Given a linked list and integers m and n, retain m nodes and then delete n nodes, repeating this pattern across the whole list. Return the resulting list as an array. (This is the classic skip-M, delete-N traversal.) Input: '[list], m, n'.

Input: '[list], m, n'.

Output: Array — the list after the pattern.

Examples

Example 1
Input: [1,2,3,4,5,6,7,8,9,10], 2, 3
Output: [1,2,6,7]
Explanation: Keep 2, delete 3, repeat.
Example 2
Input: [1,2,3,4,5,6,7,8,9,10], 1, 1
Output: [1,3,5,7,9]
Explanation: Keep 1, delete 1.
Example 3
Input: [1,2,3,4], 2, 0
Output: [1,2,3,4]
Explanation: Nothing deleted.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →