← ansys Interview Insights

ansys·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Interviewed for a software engineer role at Ansys and got a linked list removal problem. Pretty standard stuff but the edge cases around head node deletion tripped me up more than I expected.

Questions Asked (1)

Q1

Given the head of a singly linked list and an integer value, remove all nodes whose value matches that integer and return the new head.

Algorithms & Data Structures
Author's notes

The basic traversal part was fine, but I fumbled the head removal case for a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying edge cases (empty list, all nodes removed, removal at head) and then present an iterative solution using a dummy node to simplify head removal. Walk through the pointer manipulation step by step, emphasizing O(n) time and O(1) space, and test with a small example.

Pro tip: Mention that using a dummy node avoids special-casing the head, and explicitly discuss how you would test the solution with edge cases like removing the head or all nodes.

1. Clarify requirements and edge cases

Ask if the list can be empty, if all nodes might be removed, and if the value can appear multiple times. Confirm return type and that the list is singly linked.

2. Choose an approach

Decide between iterative and recursive. For interviews, iterative with a dummy node is usually preferred for O(1) space and simplicity.

3. Implement the solution

Create a dummy node pointing to head, use a current pointer to traverse, and adjust next pointers to skip nodes with the target value. Return dummy.next.

4. Analyze complexity

State that time complexity is O(n) since each node is visited once, and space complexity is O(1) for the iterative approach.

5. Test with examples

Walk through a small example, including edge cases like removing the head, removing consecutive nodes, and removing all nodes.

Key Points to Mention

  • Use of a dummy node to handle head removal uniformly
  • Pointer manipulation: prev.next = curr.next to skip nodes
  • Time complexity O(n) and space complexity O(1)
  • Edge cases: empty list, all nodes removed, removal at head/tail
  • Iterative vs recursive trade-offs (recursion uses O(n) stack space)
  • Returning the new head (dummy.next)

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.