FastPrepSwap Nodes in Pairs
Problems/Swap Nodes in Pairs

Swap Nodes in Pairs

Bloomberg LP logoBloomberg LP● MediumNEW GRADINTERNPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A new-grad report from a Bloomberg coding round names a pairwise node swap on a linked list as one of its two coding questions. It gives only the name of the task, with no statement, limits or example. We read that name as the classic swap of neighbors in pairs.

Everything else here is our choice. Nodes are paired from the front. A last node with no partner stays where it is. An empty list stays empty. The answer is checked by comparing the values from head to tail. A list has 0 to 1000 nodes with values from -1000 to 1000.

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

You are given the head of a singly linked list. Group the nodes in pairs from the front: the 1st and 2nd nodes, then the 3rd and 4th, and so on. Swap the two nodes in every pair, and return the head of the new list.

If the list has an odd number of nodes, the last node has no partner and stays where it is. An empty list stays empty.

Change the links between nodes instead of copying values from one node to another. The judge reads the values from head to tail and compares their order.

Function

swapPairs(head: ListNode) → ListNode

Examples

Example 1

head = [3,8,5,2]return = [8,3,2,5]
head
3852
→
return
8325
Moved or new

The pairs are (3, 8) and (5, 2). Swapping inside each pair gives [8, 3, 2, 5].

Example 2

head = [7,8,9,10,11]return = [8,7,10,9,11]
head
7891011
→
return
8710911
Moved or new

The pairs are (7, 8) and (9, 10). They swap to 8, 7, 10, 9.

The fifth node, 11, has no partner, so it stays last. The answer is [8, 7, 10, 9, 11].

Example 3

head = [-5]return = [-5]
head
-5
→
return
-5

One node cannot form a pair, so the list does not change. The answer is [-5].

Example 4

head = [10,20]return = [20,10]
head
1020
→
return
2010
Moved or new

The only pair is (10, 20). Swapping it gives [20, 10].

Constraints

  • The list has between 0 and 1000 nodes.
  • -1000 <= node.val <= 1000

More Bloomberg LP Onsite Interview questions

  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
  • Reverse a Sublist of a Linked ListSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • LRU CacheLotusFlare · ONSITE INTERVIEW
  • LRU CacheGimlet Labs · PHONE SCREEN
  • Remove Nth Node From End of ListDruva · ONSITE INTERVIEW
  • Merge a List In Between Two PositionsWalmart · ONSITE INTERVIEWWalmart interview questions
  • LRU CacheBNSF Railway · PHONE SCREENBNSF Railway interview questions
  • LRU CacheJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
  • LRU Cache OperationsHevo Data · ONSITE INTERVIEW

Interview reports that mention this question

  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
  • Bloomberg New Grad Interviews: 2025 vs 2026 Guide

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP 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 swapPairs(ListNode head) {
        // Write your code here.
    }
}
Checking account…