Back to Data Structures and Algorithms Interview
Data Structures and Algorithms Interview

Data Structures and Algorithms Interview

20 of 20 Completed

Assessment 1: Singly Linked Lists
Go to question details page

Singly-linked lists are a type of linked list where nodes have only one pointer: A pointer to the next element. Create a class SinglyLinkedList along with its methods:

  • add_head(element) - adds an element to the head of the list. This becomes the new head of the linked list.
  • add_tail(element) - adds an element to the tail of the list. This becomes the new tail of the linked list.
  • remove_head() -> element - removes the head and returns the value of the removed element.
  • remove_tail() -> element - removes the tail and returns the value of the removed element.
  • __contains__(item) -> bool - checks if the item is inside the list. Returns True if it is inside the list and returns False if not. This method is implemented to allow the use of Python’s in operator.
  • __getitem__(index) - returns the element at the specified index. Raises an IndexError if the index is out of bounds. This method is implemented to allow the use of Python’s [] operator.
  • __len__() - returns the length of the SinglyLinkedList.
Good job, keep it up!

100%

Completed

You have completed all sections on this learning path.

Loading pricing options