அல்கோரிதம்concept mapping
Concept mapping — linked list
TT
Testlaa Team
May 14, 2026•1 min read
Train/playlist — node mapping; invariant — next until None.
Try this in Python
from __future__ import annotations
from dataclasses import dataclass
@dataclass
class Node:
val: int
next: Node | None = None
def to_list(head: Node | None) -> list[int]:
out: list[int] = []
while head:
out.append(head.val)
head = head.next
return out
def from_list(vals: list[int]) -> Node | None:
dummy = Node(0)
cur = dummy
for x in vals:
cur.next = Node(x)
cur = cur.next
return dummy.next
# Map index -> walk steps
def get_at(head: Node | None, i: int) -> int | None:
while head and i:
head = head.next
i -= 1
return head.val if head else None
print(get_at(from_list([10, 20, 30]), 1))
Key takeaways
- Index — O(n).
- Counter walk.
- Mutable vs read-only.
Tags:
Linked listsPythonமாணவர்கள்
