Given a singly linked list, remove duplicate values in-place. Variant A (sorted list): delete repeated nodes so each value appears once using O(
-
extra space. Variant B (unsorted list): delete duplicates while preserving the first occurrence; provide two solutions—
(
-
using a hash set and
(
-
without extra memory using the runner technique. Define your ListNode type, explain correctness, analyze time and space complexity for each approach, and include tests for edge cases (empty list, single node, all duplicates, no duplicates).