Subtract Arbitrarily Long Nonnegative Decimal Strings
Company: StackAdapt
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: Subtract arbitrarily long decimal strings without integer conversion using digit-wise borrowing, unequal-length handling, and canonical leading-zero cleanup.
Constraints
- Each operand contains only ASCII decimal digits and has 1 through 2^31 − 1 characters.
- The numeric value of num1 is at least that of num2.
Examples
Input: ('1000', '7')
Expected Output: '993'
Explanation: The borrow propagates across two zero columns.
Input: ('0042', '00000017')
Expected Output: '25'
Explanation: Leading zeros affect string length without changing either value.
Hints
- Leading zeros may make the string for the smaller value longer.