Quick Overview

This question evaluates string manipulation and numeric representation skills, specifically handling decimal-point addition with arbitrary precision and reasoning about palindrome/permutation properties.

Handle palindrome & decimal addition

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

##### Question LeetCode 266. Palindrome Permutation Given two non-negative decimal number strings, implement addition that supports a decimal point. https://leetcode.com/problems/palindrome-permutation/description/

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.

Given two non-negative decimal number strings a and b, return their sum as a normalized decimal string. The strings may contain at most one decimal point. Perform digit-wise addition; do not parse the entire strings as numeric types. Normalization rules for the output: remove leading zeros in the integer part (but keep a single '0' if the number is zero), remove trailing zeros in the fractional part, and omit the decimal point if the fractional part becomes empty.

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

Hints

  1. Split each input around the decimal point into integer and fractional parts.
  2. Pad the shorter fractional part with trailing zeros so both fractions have equal length.
  3. Add fractional parts right-to-left, carrying into the integer part if needed.
  4. Add integer parts right-to-left, including any carry from the fractional sum.
  5. Trim trailing zeros from the fractional result and leading zeros from the integer result; remove the decimal point if the fractional part becomes empty.

Loading coding console...