Preparing your design workspace

Loading the problem and your saved attempt…

Design and Implement a Doubly Linked List

Design a small object-oriented doubly linked list whose insertion, removal, search, and traversal contracts remain correct at every boundary.

For this exercise, assume a caller manages one in-memory ordered collection of signed integer values through a doubly linked-list object. Design a clean object model and implement its core mutations.

The public contract must support addFirst, addLast, insertAfter a live node handle, remove a live node handle, findFirst by value, size, and forward and reverse traversal. Duplicate values are allowed.

A node handle is valid only while its node belongs to that list; passing a removed node or a handle from another list must produce a typed error and leave both lists unchanged.

Preserve these invariants after every successful mutation: head and tail are null together exactly when the list is empty, neighboring next and previous links agree, and size equals the number of reachable nodes. Assume single-threaded use.

Persistence, sorting, concurrent mutation, and lock-free traversal are outside scope. Explain any additional traversal semantics you choose, then implement enough of the design to demonstrate the invariant-preserving mutation path rather than only sketching method names.