7 kyu
Linked Lists - Get Nth Node
1,960 of 5,959JDeBolt
Description:
Linked Lists - Get Nth
Implement a GetNth()
function that takes a linked list and an integer index and returns the node stored at the Nth
index position. GetNth()
uses the C numbering convention that the first node is index 0, the second is index 1, ... and so on.
So for the list 42 -> 13 -> 666
, GetNth(1)
should return Node(13)
;
getNth(1 -> 2 -> 3 -> null, 0).data === 1
getNth(1 -> 2 -> 3 -> null, 1).data === 2
The index should be in the range [0..length-1]
. If it is not, or if the list is empty, GetNth()
should throw/raise an exception (ArgumentException
in C#, InvalidArgumentException
in PHP, Exception
in Java).
Related Kata in order of expected completion (increasing difficulty):
- Linked Lists - Push & BuildOneTwoThree
- Linked Lists - Length & Count
- Linked Lists - Get Nth Node
- Linked Lists - Insert Nth Node
- Linked Lists - Sorted Insert
- Linked Lists - Insert Sort
- Linked Lists - Append
- Linked Lists - Remove Duplicates
- Linked Lists - Move Node
- Linked Lists - Move Node In-place
- Linked Lists - Alternating Split
- Linked Lists - Front Back Split
- Linked Lists - Shuffle Merge
- Linked Lists - Sorted Merge
- Linked Lists - Merge Sort
- Linked Lists - Sorted Intersect
- Linked Lists - Iterative Reverse
- Linked Lists - Recursive Reverse
Inspired by Stanford Professor Nick Parlante's excellent Linked List teachings.
Linked Lists
Data Structures
Fundamentals
Similar Kata:
Stats:
Created | Aug 3, 2015 |
Published | Aug 3, 2015 |
Warriors Trained | 12782 |
Total Skips | 1544 |
Total Code Submissions | 21763 |
Total Times Completed | 5959 |
JavaScript Completions | 1960 |
Python Completions | 2121 |
Ruby Completions | 294 |
Java Completions | 717 |
PHP Completions | 126 |
Swift Completions | 380 |
C# Completions | 386 |
C Completions | 282 |
COBOL Completions | 3 |
CoffeeScript Completions | 8 |
Total Stars | 144 |
% of votes with a positive feedback rating | 86% of 799 |
Total "Very Satisfied" Votes | 621 |
Total "Somewhat Satisfied" Votes | 135 |
Total "Not Satisfied" Votes | 43 |