dsa · easy
Design Linked List
GreyOrangeLinked ListDesignFoundation
Implement a singly linked list with 0-based indices.
Methods
get(index)→ value at that index, or-1if out of rangeaddAtHead(val)insert before the current headaddAtTail(val)appendaddAtIndex(index, val)insert beforeindex.index == lengthis append. No-op ifindex > lengthdeleteAtIndex(index)no-op if out of range
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]