Simplified Fractions - Problem

Given an integer n, return a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator is less-than-or-equal-to n.

A fraction is simplified if the greatest common divisor (GCD) of the numerator and denominator is 1.

You can return the answer in any order.

Input & Output

Example 1 — Basic Case
$ Input: n = 2
Output: ["1/2"]
💡 Note: Only one fraction with denominator ≤ 2: 1/2 is already simplified since gcd(1,2) = 1
Example 2 — Multiple Denominators
$ Input: n = 3
Output: ["1/2", "1/3", "2/3"]
💡 Note: Denominators 2 and 3: 1/2 (gcd=1), 1/3 (gcd=1), 2/3 (gcd=1). All are simplified.
Example 3 — With Non-Simplified
$ Input: n = 4
Output: ["1/2", "1/3", "1/4", "2/3", "3/4"]
💡 Note: Skip 2/4 because gcd(2,4) = 2, so it simplifies to 1/2 which we already have.

Constraints

  • 1 ≤ n ≤ 100

Visualization

Tap to expand
Simplified Fractions Problem Overview (n = 4)Input: n = 44All Fractions:1/21/32/32/41/4GCD=1GCD=1GCD=1GCD=2GCD=13/4GCD=1Filter: Keep only fractions where GCD(numerator, denominator) = 1Simplified fractions are in lowest terms (cannot be reduced further)Output: ["1/2", "1/3", "2/3", "1/4", "3/4"]
Understanding the Visualization
1
Input
Integer n representing maximum denominator
2
Process
Generate fractions and check if simplified (GCD = 1)
3
Output
List of simplified fraction strings
Key Takeaway
🎯 Key Insight: A fraction is simplified when its numerator and denominator share no common factors (GCD = 1)
Asked in
Google 15 Microsoft 12
28.5K Views
Medium Frequency
~15 min Avg. Time
834 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen