Katkat

Compute square root to 1 decimal

UberData Scientist · Technical Screen

Last updated

This question evaluates a candidate's understanding of numerical methods, floating-point precision, and implementation of approximate functions when producing a square root rounded to one decimal place.

Problem

Given a non-negative real number x, implement a function sqrt1dp(x) that returns (\sqrt{x}) rounded (or truncated—clarify with interviewer) to one digit after the decimal point.

Requirements

  • Do not call a built-in square root function.
  • Your answer must be accurate to 1 decimal place (e.g., error < 0.05 if rounding).
  • Discuss how you would optimize the algorithm (time complexity and convergence).

Examples

  • x = 2 → 1.4
  • x = 9 → 3.0
  • x = 0 → 0.0

Clarifications to ask

  • Rounding vs truncation to 1 decimal.
  • Input range (e.g., up to 1e9?) and whether x can be non-integer.
  • Acceptable error tolerance if not using decimal formatting.