One Pass
One pointer
Array to Linked List
Easy·
1
Linear construction
O(n)
O(1)
FIG. ARRAY TO LINKED LIST● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
- A single loop builds one node per remaining value in
arr,n = len(arr). - Space
- O(1)
- Only
headandcurrare tracked; the newly allocated list nodes are the required output, not auxiliary space.
1290. Convert Binary Number in a Linked List to Integer
Easy·
2 Approachesclick to switch
1
Mathematical
O(n)
O(1)
2
Bit Manipulation
O(n)
O(1)
FIG. CONVERT BINARY NUMBER IN A LINKED LIST T● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
currwalks the list once,nbeing the number of nodes.- Space
- O(1)
- Only
numberandcurrare kept, regardless of list length.
3263. Convert Doubly Linked List to Array I
Easy·
2 Approachesclick to switch
1
Store & Return
O(n)
O(n)
2
Yield
O(n)
O(1)
FIG. CONVERT DOUBLY LINKED LIST TO ARRAY I● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
nis the number of nodes - thewhile currloop advancescurrone node at a time, visiting each node once.- Space
- O(n)
arraycollects one entry per node, growing tonvalues.
3294. Convert Doubly Linked List to Array II
Medium·
2 Approachesclick to switch
1
Store & Return
O(n)
O(n)
2
Yield
O(2n)
O(1)
FIG. CONVERT DOUBLY LINKED LIST TO ARRAY II● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
- The first
whilewalks backward fromheadto the true start of the list, and the second walks forward fromhead.nextto the end - together the two loops visit every one of thennodes in the list exactly once, with no overlap. - Space
- O(n)
arrayaccumulates one entry per node, up tonelements.
237. Delete Node in a Linked List
Medium·
1
Solution
O(1)
O(1)
FIG. DELETE NODE IN A LINKED LIST● INTERACTIVE
visualization loads as you reach it
- Time
- O(1)
node's value andnextpointer are each overwritten once fromnode.next, independent of the list's length.- Space
- O(1)
- No extra structures are allocated.
Search In Linked List
Basic·
1
Solution
O(n)
O(1)
FIG. SEARCH IN LINKED LIST● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
n= number of nodes inhead. Thewhile headloop walks the list once, stopping as soon ashead.data == xmatches or the list ends.- Space
- O(1)
- Only the
headtraversal pointer is used; nothing scales withn.
Is Linked List Length Even?
Basic·
1
Solution
O(n)
O(1)
FIG. IS LINKED LIST LENGTH EVEN● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
- The
while headloop advancesheadand incrementslengthonce per node, visiting each of thennodes exactly once. - Space
- O(1)
- Only the
lengthcounter is tracked; no extra structure is allocated.
Frequency in a Linked List
Easy·
1
Solution
O(n)
O(1)
FIG. FREQUENCY IN A LINKED LIST● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
- A single pass walks
headto the end of the list,nnodes. - Space
- O(1)
- Only the
countaccumulator is tracked.
Modular Node
Basic·
1
Solution
O(n)
O(1)
FIG. MODULAR NODE● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
nis the number of nodes in the list. Thewhile currloop advancescurronce per node, doing constant work per step.- Space
- O(1)
- Only
mod_node,curr, andindexare tracked, regardless of list length.
Remove Nodes
203. Remove Linked List Elements
Easy·
2 Approachesclick to switch
1
Iterative
O(n)
O(1)
2
Recursive
O(n)
O(n)
FIG. REMOVE LINKED LIST ELEMENTS● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
current_nodewalks the list once viacurrent_node.next, visiting each of thennodes.- Space
- O(1)
- Only
sentinelandcurrent_nodeare tracked, regardless ofn.
83. Remove Duplicates from Sorted List
Easy·
2 Approachesclick to switch
1
Iterative
O(n)
O(1)
2
Recursive
O(n)
O(n)
FIG. REMOVE DUPLICATES FROM SORTED LIST● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
current_nodewalks the list once, visiting each node exactly once.- Space
- O(1)
- Duplicates are unlinked in place; only
current_nodeis tracked.
1474. Delete N Nodes After M Nodes of a Linked List
Easy·
1
Solution
O(L)
O(1)
FIG. DELETE N NODES AFTER M NODES OF A LINKED● INTERACTIVE
visualization loads as you reach it
- Time
- O(L)
- The outer
whilekeeps advancingpthrough the "keep" loop or deleting viap.next = p.next.nextthrough the "delete" loop - every node in the original list is either advanced past or unlinked exactly once, so total work across all inner loops is bounded by the list lengthL. - Space
- O(1)
- Only
sentinelandpare allocated; nodes are deleted in place with no extra structure.
Modify Nodes
2046. Sort Linked List Already Sorted Using Absolute Values
Medium·
1
Solution
O(n)
O(1)
FIG. SORT LINKED LIST ALREADY SORTED USING AB● INTERACTIVE
visualization loads as you reach it
- Time
- O(n)
current_nodeadvances past each node exactly once; a negative node is unlinked and reinserted at the front inO(1), without restarting the scan.- Space
- O(1)
- Only
sentinel,current_node, andnext_nodeare tracked; nodes are relinked in place.
Counter
3063. Linked List Frequency
Easy·
2 Approachesclick to switch
1
Two Pass
O(n + k)
O(k)
2
One Pass
O(n)
O(k)
FIG. LINKED LIST FREQUENCY● INTERACTIVE
visualization loads as you reach it
- Time
- O(n + k)
- The first
while currloop walks allnnodes of the input list to buildcounter- one pass. - The
for freq in counter.values()loop then walks thekdistinct values to build the frequency list - a second pass. - Space
- O(k)
counterholds one entry per distinct value, and the new frequency list built fromsentinelalso hasknodes.