← Pinterest Interview Insights

Pinterest·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Pinterest SWE coding round focused on a decimal rounding problem that sounds trivial but ends up requiring a surprising amount of edge case handling. More of a logic exercise than a pure algorithms question.

Questions Asked (1)

Q1

Round the last digit of a non-negative decimal or integer using half-up rounding rules.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Sounds like a five-minute warmup until you actually start coding it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the input format (string or number) and the exact rounding rule (half-up) before coding. Then implement a robust solution that handles edge cases like trailing nines and integer inputs, and discuss trade-offs between string manipulation and arithmetic approaches.

Pro tip: Mention that half-up rounding is not the default in many languages (e.g., Python's round uses banker's rounding), so you must implement it manually. Also, consider that the last digit might be after a decimal point or the units digit of an integer.

1. Clarify requirements and edge cases

Ask whether the input is a string or number, and confirm that 'last digit' means the least significant digit (units place for integers, last decimal place for decimals). Discuss handling of trailing nines, negative numbers (though non-negative specified), and very large numbers.

2. Choose representation and algorithm

Decide between string manipulation (safer for precision) and arithmetic (simpler but may have floating-point issues). For string approach, parse the last digit, apply half-up rule, and handle carry propagation.

3. Implement rounding logic

If last digit < 5, drop it; if >= 5, increment the previous digit and propagate carry. For integers, incrementing may add a new digit (e.g., 99 -> 100). For decimals, ensure the decimal point is preserved if needed.

4. Test with edge cases

Test cases: 1.4 -> 1, 1.5 -> 2, 9.9 -> 10, 99 -> 100, 0 -> 0, 0.5 -> 1, 123.45 -> 123.5 (if last digit is 5? Actually last digit is 5, so round up to 123.5? Wait, careful: if number is 123.45, last digit is 5, so round up the previous digit (4) to 5, resulting in 123.5). Also test 1.999 -> 2.0? Actually last digit is 9, round up previous digit (9) causing carry, etc.

5. Discuss trade-offs and optimizations

Compare string vs arithmetic approaches: string avoids floating-point errors but may be slower for very long numbers; arithmetic is faster but risky with floats. Mention potential use of BigDecimal or similar for precision.

Key Points to Mention

  • Half-up rounding rule: round up if the digit is 5 or more, otherwise round down.
  • Carry propagation when incrementing a 9 (e.g., 199 -> 200).
  • Handling of integers vs decimals: for integers, the last digit is the units place; for decimals, it's the last decimal place.
  • Edge cases: all nines (e.g., 999 -> 1000), zero, and numbers with trailing zeros (e.g., 1.50 -> 1.5? Actually last digit is 0, so drop it, resulting in 1.5).
  • Trade-offs: string manipulation ensures precision but may be less efficient; arithmetic is faster but can introduce floating-point errors.
  • Language-specific rounding behavior: many languages use banker's rounding by default, so explicit implementation is needed.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.