DataStructures-and-Algorithms

Code Challenge

k-th value from the end of a linked list.

Specifications

Challenge Setup & Execution

Branch Name: linked-list-kth

Challenge Type: Extending an Implementation

Feature Tasks

Write the following method for the Linked List class:

Example

ll.kthFromEnd(k)

Input ll Arg k Output
head -> {1} -> {3} -> {8} -> {2} -> X 0 2
head -> {1} -> {3} -> {8} -> {2} -> X 2 3
head -> {1} -> {3} -> {8} -> {2} -> X 6 Exception

Unit Tests

Write tests for the following scenarios, and any other cases that help you ensure your code is working as expected.

  1. Where k is greater than the length of the linked list
  2. Where k and the length of the list are the same
  3. Where k is not a positive integer
  4. Where the linked list is of a size 1
  5. “Happy Path” where k is not at the end, but somewhere in the middle of the linked list

Unit tests must be passing before you submit your final solution code.

Stretch Goal

Once you’ve achieved a working solution, implement a method that finds the node at the middle of the Linked List.

Requirements

Ensure your complete solution follows the standard requirements.

  1. Write unit tests
  2. Follow the template for a well-formatted README
  3. Submit the assignment following these instructions