CrackML by @ml.with.umang
Interview questions / Python & DSA
Python & DSA interview question

Add Decimal Numbers as Strings

Add two decimal numbers represented as strings without converting them to floating point.

mediumcodingEvidence 77/1001 source reportMeta

The 60-second answer

Use align integer/fractional parts and perform digit-by-digit addition with carry. Target O(n) time and O(n) output space.

Build the answer in this order

1
Clarify constraints

Use align integer/fractional parts and perform digit-by-digit addition with carry.

2
Choose the approach

Target O(n) time and O(n) output space.

3
Prove complexity

Call out edge cases such as different fractional lengths, carry across the decimal point, leading/trailing zeros, and missing decimal parts.

4
Test edge cases

Explain the invariant before coding, then dry-run a small case and state time/space complexity.

A useful interview mental model

This is the shape of a strong answer—not a script to memorize.

01Clarify
02Approach
03Implement
04Test
05Complexity

Senior-level signal

  • Avoid floating point entirely and normalize output only after preserving exact arithmetic semantics.
  • Mention arbitrary precision and locale/formatting concerns if this becomes production code.

What the interviewer is really testing

Problem decomposition, correctness, data-structure choice, complexity reasoning, and clean implementation under pressure.

Likely follow-up questions

Can you improve the time or space complexity?
Which edge case is most likely to break this solution?
How would you test this under interview time pressure?

Common weak-answer patterns

  • Starting to code before constraints are clear.
  • Giving complexity without explaining why it is correct.
  • Skipping adversarial and boundary cases.