Handle palindrome & decimal addition
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates string manipulation and numeric representation skills, specifically handling decimal-point addition with arbitrary precision and reasoning about palindrome/permutation properties.
Constraints
- 1 <= len(a), len(b) <= 100000
- a and b contain only digits and at most one '.'
- If '.' is present, there is at least one digit on both sides (matches regex: ^[0-9]+(\.[0-9]+)?$)
- No signs, spaces, or exponent notation
- Must not convert the entire strings to integers/floats/decimals; use digit-wise addition
- Return must be normalized as described
Examples
Input:
Expected Output: 13
Input:
Expected Output: 1000
Input:
Expected Output: 16
Input:
Expected Output: 0
Input:
Expected Output: 579.789
Input:
Expected Output: 0
Input:
Expected Output: 1.24
Input:
Expected Output: 1000
Hints
- Split each input around the decimal point into integer and fractional parts.
- Pad the shorter fractional part with trailing zeros so both fractions have equal length.
- Add fractional parts right-to-left, carrying into the integer part if needed.
- Add integer parts right-to-left, including any carry from the fractional sum.
- Trim trailing zeros from the fractional result and leading zeros from the integer result; remove the decimal point if the fractional part becomes empty.