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
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)
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code