dsa · easy

Design Linked List

Implement a **singly linked list** of nodes. Each node holds val and next. Do not back this with a Python array — the interview is the pointer walk.

Indices are 0-based.

Methods

Fill in the MyLinkedList class. The starter already walks ops / args and calls your methods — leave the driver at the bottom as-is. Constructors contribute null; booleans print as true / false.

Example

`` MyLinkedList() → null addAtHead(1) → null addAtTail(3) → null addAtIndex(1, 2) → null get(1) → 2 deleteAtIndex(1) → null get(1) → 3 ``

Constraints

Calls <= 1000

Examples

Example 1

Input:
["MyLinkedList","addAtHead","addAtTail","addAtIndex","get","deleteAtIndex","get"]
[[],[1],[3],[1,2],[1],[1],[1]]

Expected:
[null,null,null,null,2,null,3]

Open in the Dojo editor