As reported: IBM Cloud & AI Engineer (Bengaluru, 6.5 years of experience, October 2026), technical round 1: after reversing a linked list, the candidate was given an existing implementation of merging two sorted linked lists and asked to debug it.
You are given an implementation of mergeTwoLists that is supposed to merge two sorted linked lists into one sorted list by splicing their nodes. It runs, but some inputs come back wrong. Find the bug and fix it. Open Practice to read it in the editor, in any of the five languages.
This is LeetCode 21 — Merge Two Sorted Lists.
Merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the first two lists.
Example:
Input: l1 = [1,2,4], l2 = [1,3,4]
Output: [1,1,2,3,4,4]
Input: l1 = [], l2 = []
Output: []
Code runner format: one JSON value per line, in argument order (list1, list2), as in LeetCode's test cases. Implement mergeTwoLists; the harness prints the result as compact JSON (sorted first when any order is accepted).