Fraction to Recurring Decimal

Medium · Math & Number Theory · about 25 minutes

Asked at Google, Amazon, Meta, Microsoft.

Given a numerator and a non-zero denominator, return the fraction as a decimal string. If the fractional part repeats, enclose the repeating part in parentheses, e.g. 1/3 = "0.(3)", 4/333 = "0.(012)". The answer is unique.

Related guides