FastPrepRemove Linked List Nodes with a Given Value
Problems/Remove Linked List Nodes with a Given Value

Remove Linked List Nodes with a Given Value

Expedia logoExpedia● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An anonymous entry about an Expedia intern campus process in September 2022 lists this task by name in the second of three video calls held on one day. Only the name is given there, with no input format, examples or limits.

Here, you get the first node of a singly linked list and a target number. You drop every node that holds that number and return the first node of what is left. An empty result is null. A list has 0 to 1000 nodes, and every node value and the target are whole numbers from 0 to 10^5. Only the returned list is checked.

Our version is about 95% the same as the reported question.

You are given head, the first node of a singly linked list, and an integer val. Remove every node whose value equals val and return the first node of the list that is left.

The nodes that stay keep their original order. If every node is removed, or the list was empty, return null.

Function

removeElements(head: ListNode, val: int) → ListNode

Examples

Example 1

head = [6,2,6,6,3]val = 6return = [2,3]
head
62663
Removed
→
return
23
Moved or new

The nodes that hold 6 are the 1st, 3rd and 4th. Removing them leaves 2 -> 3. The 3rd and 4th nodes are next to each other, so both must go.

Example 2

head = [1,4,1]val = 7return = [1,4,1]
head
141
→
return
141

No node holds 7, so the list is returned unchanged.

Example 3

head = [5,5]val = 5return = []
head
55
return
empty

Every node holds 5, so all of them are removed and the answer is null, an empty list.

Constraints

  • 0 <= n <= 1000, where n is the number of nodes.
  • Every node value is between 0 and 10^5.
  • 0 <= val <= 10^5
  • Values may repeat.

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Reverse a Singly Linked ListMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Reverse a Singly Linked ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Sorted Doubly Linked List to Balanced BST In PlaceSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Reverse Nodes in K-GroupAmazon · ONSITE INTERVIEW
  • Merge K Sorted Linked ListsThe Walt Disney Company · OA · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Merge K Sorted ListsSkydio · ONSITE INTERVIEWSkydio interview questions
  • Merge K Sorted Linked Lists Into OneCapital One · ONSITE INTERVIEWCapital One interview questions
  • Reverse a Linked ListCisco · PHONE SCREENCisco interview questions
  • Reverse a Linked ListApple · PHONE SCREENApple interview questions
  • Reverse a Singly Linked ListChubb · PHONE SCREENChubb interview questions

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode removeElements(ListNode head, int val) {
        // Write your code here.
    }
}
Checking account…