Goldman Sachs Online Assessment Question | String | GCD | Maths
- Result
- Ongoing
- Posted
- 26 Aug 2025
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)
- 01
Simplify Fraction
Data Structures & Algorithms · Easy
Problem: Simplify Fraction
You are given a string
sin the form"a/b", whereaandbare 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"