DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Two Pointer

Remove Nth Node From End

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Remove Nth Node From End** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Two-pointer with n-gap lead **Edge Cases to Consider:** - (1) Remove head (n = list length) - (2) Single node - (3) Two nodes, remove first or second

Examples

Example 1
Input: [1,2,3,4,5], 2
Output: [1,2,3,5]
Explanation: Remove 4th from start
Example 2
Input: [1], 1
Output: []
Explanation: Single node removed
Example 3
Input: [1,2], 1
Output: [1]
Explanation: Remove last node

Constraints

  • ▪1 <= data.length <= 10^5
  • ▪Memory complexity must be O(1) or O(k)
  • ▪Ensure non-overlapping pointer access

Watch Out For Edge Cases

  • ▪Remove head (n = list length)
  • ▪Single node
  • ▪Two nodes, remove first or second
Frequently Asked At
AmazonMicrosoftGoogleMetaAdobe