Terrible LeetCode in Kotlin: #19 Remove Nth Node From End of List

Опубликовано: 10 Июль 2026
на канале: Personal Finance with Raymond
23
0

Another day, another LeetCode question (for now). Today, I'm running through #19 Remove Nth Node From End of List. The problem provides a head of a linked list as well as an integer n, with your job being to return the head of the new list with the node n units from the end removed.

This one took longer than I would have liked, and I will be exploring this problem again to make sure that it really sticks. The idea is to use a two-pointer approach, where one pointer is n units or so away and the other lags behind. Through some clever logic, we can know that when the fast pointer is at the end of the list, then the current pointer is at the node before the one we wish to remove. We then perform the operation and return, resulting in an algorithm that runs in O(n) time, where n is the number of items in the list, not the n parameter.

I work in Kotlin as my LeetCode programming language because my current focus is on Android app development. Kotlin is interoperable with Java, so the solution should be relatively similar albeit with some more boilerplate checks for nulls and such.

Current Grind:
Grind75 list, 22 weeks/16 hours per week, [90/169]
(https://www.techinterviewhandbook.org...)

Chapters:
00:00 - Problem discussion, coding begins (Two pointers)