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
Node.GetNth(1 -> 2 -> 3 -> null, 0).Data == 1
Node.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):

Inspired by Stanford Professor Nick Parlante's excellent Linked List teachings.

http://cslibrary.stanford.edu/103/LinkedListBasics.pdf

http://cslibrary.stanford.edu/105/LinkedListProblems.pdf

Linked Lists
Data Structures
Fundamentals

Stats:

CreatedAug 3, 2015
PublishedAug 3, 2015
Warriors Trained12782
Total Skips1544
Total Code Submissions21763
Total Times Completed5959
JavaScript Completions1960
Python Completions2121
Ruby Completions294
Java Completions717
PHP Completions126
Swift Completions380
C# Completions386
C Completions282
COBOL Completions3
CoffeeScript Completions8
Total Stars144
% of votes with a positive feedback rating86% of 799
Total "Very Satisfied" Votes621
Total "Somewhat Satisfied" Votes135
Total "Not Satisfied" Votes43
Ad
Contributors
  • JDeBolt Avatar
  • jhoffner Avatar
  • CIS 122 Avatar
  • NaMe613 Avatar
  • is151014 Avatar
  • donaldsebleung Avatar
  • Voile Avatar
  • Souzooka Avatar
  • Bubbler Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • avermakov Avatar
  • LosBlobbos Avatar
Ad