Member-only story

Remove Nth Node from the Back of the Linked List | Linked List | Coding Interview

Ganesh Prasad
5 min readSep 18, 2022

--

I can think of two ways to solve this problem; one using a stack and another without a stack. The time complexity will be the same in both cases, and the space requirement is linear in the stack approach and constant in the iterative one. Let’s see how.

I have been writing detailed articles on interview problems for quite some time; I would like you to read and get help from this pattern-wise list 🔥 of problems.

Table of Contents

  1. Description
  2. Iterative solution
  3. Code and Complexities
  4. Stack-based solution (in short)

Description

Given a linked list with a pointer to its head and an integer n. Delete the nth node from the back of the linked list.

Suppose we have a linked list with the following nodes, and we want to delete the 9th from behind, which is holding “F.”

--

--

Ganesh Prasad
Ganesh Prasad

Written by Ganesh Prasad

Backend Developer at Appscrip | C++ veteran, 💜 Dart

No responses yet