Back to questions

Generate Fractions Blackstone Python Interview Question

Generate Fractions

Blackstone Python Interview Question

Given an integer , generate all simplified fractions between and (exclusive) where the denominator is less than or equal to . A fraction is simplified if the numerator and denominator have no common divisors other than .

Return a sorted list of fractions, where each fraction is represented as .

For example:

  • If n=3n = 3, return [[1, 2], [1, 3], [2, 3]]
  • If n=4n = 4, return [[1, 2], [1, 3], [1, 4], [2, 3], [3, 4]]
  • If n=5n = 5, return [[1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [2, 5], [3, 4], [3, 5], [4, 5]]

Input

Python

Output