pytudes._2021.utils.linked_list

https://www.educative.io/courses/grokking-the-coding-interview/N7rwVyAZl6D

Module Contents

Classes

ListNode

Notes:

Functions

convert_list_to_linked_list(arr[,Β recursive])

Utility fn for easier testing

Attributes

NodeType

class pytudes._2021.utils.linked_list.ListNode(val, next_node=None)[source]
Notes:
β€œNodeType” is a forward reference

Forward reference syntax: annotation as a string literal See Also: https://www.python.org/dev/peps/pep-0484/#id28

Parameters:
  • val (Any) –

  • next_node (NodeType) –

as_list()[source]
pytudes._2021.utils.linked_list.convert_list_to_linked_list(arr, recursive=False)[source]

Utility fn for easier testing

Args:

arr: input array of elements to convert recursive: whether or not to perform conversion recursively

Returns:

The head of the linked list derived from arr

Examples:
>>> convert_list_to_linked_list([2,4,6,8,10], recursive=False).as_list()
[2, 4, 6, 8, 10]
>>> convert_list_to_linked_list([2,4,6,8,10], recursive=True).as_list()
[2, 4, 6, 8, 10]
>>> assert(convert_list_to_linked_list([]) is None)
Parameters:

arr (list[Any]) –

Return type:

NodeType

pytudes._2021.utils.linked_list.NodeType