Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: What is the largest integer x with x² ≤ 2,000,000,000 (the floor of the square root of 2 × 10⁹)?

  1. A. 44722
  2. B. 44721
  3. C. 31622
  4. D. 141421

Correct answer: B. 44721

44721² = 1,999,967,841 ≤ 2 × 10⁹ < 44722² = 2,000,057,284, so the floor is 44721 (binary search with x·x ≤ n). Returning the ceiling gives 44722, √(10⁹) gives 31622, and √(2 × 10¹⁰) gives 141421.

More Coding Interview Problems questions

Exams that ask this topic