373. Delete N Nodes After M Nodes

MediumLinked ListLinked ListSimulation

Given a linked list and two integers m and n, traverse the list keeping the first m nodes, then deleting the next n nodes, and repeat this pattern until the end. Return the resulting list as an array. Input: '[list], m, n'.

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

Output: Array — the list after the skip/delete pattern.

Examples

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

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →