Goldman Sachs Online Assessment Question | String | GCD | Maths

Result
Ongoing
Posted
26 Aug 2025
300 reads

Summary

I recently encountered a problem during my Goldman Sachs Online Assessment related to simplifying fractions, which required applying GCD concepts.

How it went

During my recent online assessment for Goldman Sachs, I was presented with a problem that involved simplifying fractions. The core task was to take a string in the format "a/b" and reduce it to its lowest terms, ensuring the denominator remains positive. It was a straightforward implementation once the logic for handling negative numbers and using the greatest common divisor (GCD) was clear.

Questions asked (1)

  1. 01

    Simplify Fraction

    Data Structures & Algorithms · Easy

    Problem: Simplify Fraction

    You are given a string s in the form "a/b", where a and b are integers (which may be positive or negative).

    Your task is to reduce the fraction into its lowest terms.

    • If the fraction reduces to an integer, return the integer (as a string).
    • If not, return the simplified fraction in the form "p/q".
    • Ensure the denominator is always positive (move any negative sign to the numerator).

    Examples

    Input: "13/12"
    Output: "13/12"

    Input: "4/6"
    Output: "2/3"

    Input: "10/100"
    Output: "1/10"

    Input: "100/400"
    Output: "1/4"

    Input: "7/35"
    Output: "1/5"

    Input: "-12/13"
    Output: "-12/13"

    Input: "12/-4"
    Output: "-3"

    Input: "-8/-4"
    Output: "2"

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Goldman Sachs recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

Be the first to share your thoughts and start the discussion!