← Ansys Interview Insights

Ansys·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Coding round at Ansys for a software engineer position. Pretty standard linked list problem but the edge cases around head removal tripped me up more than I expected.

Questions Asked (1)

Q1

Given the head of a singly linked list and an integer val, remove all nodes where the node's value equals val and return the new head.

Algorithms & Data Structures
Author's notes

Thought I had this immediately and started coding without thinking through the head removal case.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints and edge cases, then propose an iterative solution using a dummy node to simplify head removal. Walk through the algorithm step-by-step, emphasizing pointer manipulation and termination conditions, and analyze time and space complexity.

Pro tip: Mention that using a dummy node elegantly handles cases where the head itself needs to be removed, avoiding special-case code. Also, discuss potential pitfalls like losing references to the next node when deleting, and how to avoid them.

1. Clarify requirements and edge cases

Ask about input constraints (e.g., empty list, all nodes equal val, val not present) and whether the list can be modified in place. Confirm return type and any memory constraints.

2. Propose an approach

Suggest using a dummy node pointing to the head, then iterate with a current pointer to skip nodes with value equal to val. This handles head removal uniformly.

3. Walk through the algorithm

Describe initializing dummy node, setting prev to dummy, and iterating while current is not null. If current.val equals val, set prev.next to current.next; else move prev to current. Finally, return dummy.next.

4. Analyze complexity and test

State time complexity O(n) and space O(1). Provide examples, including edge cases, and mentally test the code to ensure correctness.

Key Points to Mention

  • Use of dummy node to simplify edge cases (e.g., removing head).
  • Iterative traversal with two pointers (prev and current).
  • Time complexity O(n) and space complexity O(1).
  • Handling of edge cases: empty list, all nodes removed, val not found.
  • Importance of updating pointers correctly to avoid losing nodes.
  • Potential follow-up: recursive solution or if list is doubly linked.

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