FastPrepSubtract Forward-Order Linked-List Numbers
Problems/Subtract Forward-Order Linked-List Numbers

Subtract Forward-Order Linked-List Numbers

Microsoft logoMicrosoft● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft onsite interview. The report points to subtracting linked lists with digits in forward order, by comparing it to the matching addition exercise. It leaves out the sign, leading zeros, the range of values and the size rules. Our version is about 82% the same as the reported question.

Two nonempty singly linked lists represent nonnegative integers in forward digit order. Each node stores one decimal digit. Return a new forward-order linked list representing minuend - subtrahend.

The inputs have no leading zero unless the entire number is zero, and the value represented by minuend is at least the value represented by subtrahend. The result must have no leading zero; represent zero with one node containing 0. Do not convert either complete number to a built-in numeric type.

Function

subtractForwardOrder(minuend: ListNode, subtrahend: ListNode) → ListNode

Examples

Example 1

minuend = [7,2,4,3]subtrahend = [5,6,4]return = [6,6,7,9]
minuend
7243
subtrahend
564
return
6679

The lists represent 7243 and 564. Their difference is 6679.

Example 2

minuend = [1,0,0,0]subtrahend = [1]return = [9,9,9]
minuend
1000
subtrahend
1
return
999

Subtracting 1 from 1000 propagates a borrow through three zero digits and yields 999.

Example 3

minuend = [5]subtrahend = [5]return = [0]
minuend
5
subtrahend
5
return
0

Equal inputs have difference zero, represented by a single 0 node.

Constraints

  • Each list contains between 1 and 10^5 nodes.
  • 0 <= node.val <= 9
  • Neither input has a leading zero unless it is the single-node number 0.
  • The represented value of minuend is at least the represented value of subtrahend.

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Add Two Numbers IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Add Forward Linked-List Numbers Using RecursionPeopleStrong · PHONE SCREENPeopleStrong interview questions
  • Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
  • Evaluate a Prefix ExpressionGoogle · ONSITE INTERVIEWGoogle interview questions
  • Min StackCapital One · PHONE SCREEN · ONSITE INTERVIEWCapital One interview questions
  • Add Two Numbers Stored in Reversed ListsExpedia · ONSITE INTERVIEWExpedia interview questions
  • Add Numbers Stored in Four-Digit ChunksZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
  • Max StackLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Max StackZipline · ONSITE INTERVIEW
  • Basic Calculator IITypeSafe AI · OA

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft 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 subtractForwardOrder(ListNode minuend, ListNode subtrahend) {
      // write your code here
    }
}
Checking account…