Bird
Raised Fist0
DSA Typescriptprogramming~10 mins

Delete a Node from Circular Linked List in DSA Typescript - Interactive Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the circular linked list is empty before deletion.

DSA Typescript
if (head === [1]) {
  return null;
}
Drag options to blanks, or click blank then click option'
Aundefined
Bnull
C0
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or false instead of null to check for empty list.
Checking for undefined which is not used here.
2fill in blank
medium

Complete the code to find the last node in the circular linked list.

DSA Typescript
let current = head;
while (current.next !== [1]) {
  current = current.next;
}
Drag options to blanks, or click blank then click option'
Ahead
Bnull
Cundefined
Dcurrent
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for null or undefined which does not exist in circular lists.
Using current instead of head in the condition.
3fill in blank
hard

Fix the error in updating the head when deleting the head node.

DSA Typescript
if (head.value === key) {
  last.next = [1];
  head = [1];
  return head;
}
Drag options to blanks, or click blank then click option'
Ahead.next
Bnull
Clast
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Setting last.next to null breaks the circular link.
Setting last.next to last itself causes infinite loop.
4fill in blank
hard

Fill both blanks to delete a node with a given key inside the circular linked list.

DSA Typescript
let current = head;
while (current.next !== head && current.next.value !== [1]) {
  current = current.next;
}
if (current.next.value === [2]) {
  current.next = current.next.next;
}
Drag options to blanks, or click blank then click option'
Akey
Bhead
Cvalue
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using head or null instead of the key value.
Not checking current.next.value before deletion.
5fill in blank
hard

Fill all three blanks to complete the delete function for a circular linked list.

DSA Typescript
function deleteNode(head: Node | null, key: number): Node | null {
  if (head === [1]) return null;
  let last = head;
  while (last.next !== head) {
    last = last.next;
  }
  if (head.value === key) {
    last.next = [2];
    head = [3];
    return head;
  }
  let current = head;
  while (current.next !== head && current.next.value !== key) {
    current = current.next;
  }
  if (current.next.value === key) {
    current.next = current.next.next;
  }
  return head;
}
Drag options to blanks, or click blank then click option'
Anull
Bhead.next
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Using head instead of null for empty check.
Not updating last.next correctly when deleting head.
Not moving head to head.next after deletion.

Practice

(1/5)
1. What happens when you delete the only node in a circular linked list?
easy
A. The list becomes empty (null).
B. The list still contains the deleted node.
C. The list points to itself indefinitely.
D. The list throws an error.

Solution

  1. Step 1: Understand the single node case

    When there is only one node, it points to itself forming a circle.
  2. Step 2: Delete the only node

    Removing this node leaves no nodes, so the list becomes empty (null).
  3. Final Answer:

    The list becomes empty (null). -> Option A
  4. Quick Check:

    Single node deleted = empty list [OK]
Hint: Deleting last node empties the list [OK]
Common Mistakes:
  • Assuming list still has nodes after deleting the only node
  • Not setting head to null after deletion
2. Which of the following is the correct way to update the previous node's next pointer when deleting a node in a circular linked list?
easy
A. prev.next = node.next;
B. node.next = prev.next;
C. prev = node.next;
D. node = prev.next;

Solution

  1. Step 1: Identify the pointer to update

    To remove a node, the previous node's next pointer must skip the node to delete.
  2. Step 2: Update the previous node's next pointer

    Set prev.next to node.next to bypass the node being deleted.
  3. Final Answer:

    prev.next = node.next; -> Option A
  4. Quick Check:

    prev.next points to node.next [OK]
Hint: Prev node's next skips deleted node [OK]
Common Mistakes:
  • Assigning node.next to prev.next instead of the other way
  • Changing the node variable instead of prev.next
3. Consider the circular linked list: 10 -> 20 -> 30 -> (back to 10). If we delete the node with value 20, what will be the new list?
medium
A. 10 -> 20 -> 30 -> (back to 10)
B. 10 -> 30 -> (back to 10)
C. 20 -> 30 -> (back to 20)
D. 30 -> 10 -> (back to 30)

Solution

  1. Step 1: Identify node to delete and its previous node

    Node with value 20 is between 10 and 30. Previous node is 10.
  2. Step 2: Update previous node's next pointer

    Set 10's next pointer to 30, skipping 20.
  3. Final Answer:

    10 -> 30 -> (back to 10) -> Option B
  4. Quick Check:

    Deleted 20, list links 10 to 30 [OK]
Hint: Link previous node to next of deleted node [OK]
Common Mistakes:
  • Not updating the previous node's next pointer
  • Deleting wrong node or not updating links
4. Given this TypeScript code snippet to delete a node from a circular linked list, what is the error?
function deleteNode(head: Node | null, key: number): Node | null {
  if (!head) return null;
  let curr = head, prev = null;
  do {
    if (curr.data === key) {
      if (prev) prev.next = curr.next;
      else head = curr.next;
      return head;
    }
    prev = curr;
    curr = curr.next;
  } while (curr !== head);
  return head;
}
medium
A. Does not handle the empty list case.
B. Uses 'do-while' incorrectly causing infinite loop.
C. Returns null even if node is not found.
D. Does not update the tail node's next pointer when deleting head.

Solution

  1. Step 1: Analyze deletion of head node

    If deleting head, code sets head to curr.next but does not update tail's next pointer.
  2. Step 2: Identify missing tail update

    In circular list, tail's next must point to new head to maintain circularity.
  3. Final Answer:

    Does not update the tail node's next pointer when deleting head. -> Option D
  4. Quick Check:

    Tail.next must update on head deletion [OK]
Hint: Update tail's next when head is deleted [OK]
Common Mistakes:
  • Ignoring tail pointer update after head deletion
  • Assuming head change auto-updates tail's next
5. You have a circular linked list with nodes: 5 -> 10 -> 15 -> 20 -> (back to 5). You want to delete the node with value 5 (head node). Which steps correctly delete the head and maintain the circular list?
hard
A. Delete head node and set head to null.
B. Set head to head.next only, no other changes.
C. Find tail node, set tail.next to head.next, update head to head.next.
D. Find tail node, set tail.next to null, update head to head.next.

Solution

  1. Step 1: Find the tail node

    Traverse list to find node whose next points to head (value 20).
  2. Step 2: Update tail's next pointer and head

    Set tail.next to head.next (node with value 10), then update head to head.next.
  3. Final Answer:

    Find tail node, set tail.next to head.next, update head to head.next. -> Option C
  4. Quick Check:

    Tail.next points to new head after deletion [OK]
Hint: Update tail.next before changing head [OK]
Common Mistakes:
  • Not updating tail.next causing broken circular link
  • Setting tail.next to null breaks circular list
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard