Question bank › Math
Dsa Math Hard

Rational Approximation

Given a real number x and an integer n, find the best rational approximation of x in the form of a fraction a/b, such that 1 ≤ b ≤ n and a and b are coprime. Output the fraction as 'a/b'. If multiple fractions a/b exist, return the one with the smallest a. The input starts with the float x followed by integer n. Example: Input: 2.5 5 Output: 5/2

Key concepts

number theoryfractionsapproximation

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.