Design Linked List
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Implement your own singly (or doubly) linked list of integers. Indices are 0-based.
- MyLinkedList() creates an empty list.
- get(index) returns the value at index, or -1 if index is not a valid position.
- addAtHead(val) inserts val before the first element.
- addAtTail(val) appends val after the last element.
- addAtIndex(index, val) inserts val so that it ends up at position index. If index equals the length, this appends. If index is greater than the length, nothing happens.
- deleteAtIndex(index) removes the element at index if that position exists; otherwise nothing happens.
Do not use a built-in list type to hold the elements.
Examples
Constraints
- `0 <= index, val <= 1000`
- At most 2000 calls in total.
- Do not use a built-in linked list or array to store elements.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.