FastPrepFraction to Recurring Decimal
Problems/Fraction to Recurring Decimal

Fraction to Recurring Decimal

Goldman Sachs logoGoldman Sachs● MediumFULLTIMEONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Goldman Sachs superday report links the exact Fraction to Recurring Decimal exercise and says the test cases matched. This practice version is an approximately 99% match.

Given signed integers numerator and nonzero denominator, return their exact decimal representation.

If the fractional part repeats, enclose the shortest repeating suffix in parentheses. Do not include unnecessary trailing zeroes.

Function

fractionToDecimal(numerator: int, denominator: int) → String

Examples

Example 1

numerator = 1denominator = 2return = "0.5"

The decimal terminates.

Example 2

numerator = 4denominator = 333return = "0.(012)"

The remainder repeats after the digits 012.

Constraints

  • -2^31 <= numerator <= 2^31 - 1
  • -2^31 <= denominator <= 2^31 - 1
  • denominator != 0

More Goldman Sachs Onsite Interview questions

  • Knight Probability in ChessboardONSITE INTERVIEW · Seen Nov 2026
  • Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Minimum Meeting Rooms Without a Sweep LineONSITE INTERVIEW · Seen Oct 2026
  • First Non-Repeating CharacterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Root of the Largest TreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Dungeon HealthONSITE INTERVIEW · Seen Sep 2026
  • Insert, Delete, And Get Random In Constant TimeONSITE INTERVIEW · Seen Sep 2026
  • Least Recently Used CacheONSITE INTERVIEW · Seen Sep 2026
  • Staircase Search In A Sorted MatrixONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Reconstruct Digits from Jumbled English WordsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
  • N-gram Language Model with Add-Alpha SmoothingGoogle · ONSITE INTERVIEWGoogle interview questions
  • Rank Bipedal Dinosaurs by SpeedMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
  • Minimum Anagram PeriodVisa · OAVisa interview questions
  • Maximum Equal Parts for PrefixesAmazon · OA
  • Per-Segment SpeedingOnePay · PHONE SCREENOnePay interview questions
  • Find Accounts with Negative Converted BalancesStripe · PHONE SCREENStripe interview questions
  • Minimum Anagram PeriodWells Fargo · OAWells Fargo interview questions
All Goldman Sachs interview questionsSee Goldman Sachs hiring insights
Saved
class Solution {
    public String fractionToDecimal(int numerator, int denominator) {
      // write your code here
    }
}
Checking account…