Check Palindrome and Add Decimal Strings
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates string-processing and numeric representation competencies, focusing on character-frequency reasoning for palindrome permutation detection and implementation of arbitrary-precision addition for decimal strings.
Constraints
- 1 <= len(s) <= 200000
- s consists only of lowercase English letters 'a' to 'z'
- 1 <= len(a), len(b) <= 100000
- a and b match regex: ^\d+(\.\d+)?$ (no sign, no thousand separators)
- Numbers are non-negative
- Do not use built-in big integers/decimals for addition; implement digit-by-digit string addition
- Return the lexicographically smallest palindrome if possible; otherwise return empty string
Hints
- A string can be permuted into a palindrome iff at most one character has an odd frequency.
- To get the lexicographically smallest palindrome, build the first half by placing characters in ascending order, use the single odd-count character as the center (if any), and mirror the first half.
- For decimal addition, split into integer and fractional parts, pad fractional parts to equal length, add from right to left with carry.
- Normalize the result: strip leading zeros in the integer part (leave at least one zero), strip trailing zeros in the fractional part, and drop the decimal point if the fractional part becomes empty.