Skip to main content
Back to problems
Leetcode
Medium
Linked Lists
Design
Amazon
Microsoft
707. Design Linked List

Design a linked list data structure that supports indexed insert, delete, read, and prepend/append operations.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.

Design Linked List

gfg
Problem Statement

Design a Linked List

Implement a custom linked list with the following operations:

  • get(index): return the value at the given index
  • addAtHead(val): insert a node with value val at the front
  • addAtTail(val): insert a node with value val at the end
  • addAtIndex(index, val): insert a node with value val before the node currently at index
  • deleteAtIndex(index): delete the node at index

The list is initially empty.

Your implementation should maintain correct node links and handle out-of-range indices safely.

Notes

  • Indices are zero-based.
  • If index is invalid for a read or delete operation, return a safe failure value or do nothing as appropriate.
  • Insertions at index == size are valid and append to the end.
  • Negative indices are invalid.

Input Format

The data structure is used through a sequence of method calls:

  • get(index)
  • addAtHead(val)
  • addAtTail(val)
  • addAtIndex(index, val)
  • deleteAtIndex(index)

Each call provides integer arguments.

Output Format

  • get(index) returns the value at the requested position, or -1 if the index is invalid.
  • Update operations modify the linked list in place and do not return a value.

Constraints

  • 0≤0 \le number of operations ≤\le large
  • Values and indices are integers
  • Indexing is zero-based
  • Invalid insert/delete positions should be ignored

Because this is a design problem, exact platform constraints may vary by version.

Examples
Sample cases returned by the problem API.

Example 1

Input

[

Output

-

Explanation

A complete interactive example is omitted here because the problem is usually judged by method calls rather than a single input/output pair.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.