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⁹)?
- A. 44722
- B. 44721
- C. 31622
- 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
- Problem: What is the sum of the first 50 odd positive integers (1 + 3 + 5 + … + 99)?
- Problem: In a binary-tree-free DFS on the undirected graph with edges 0-1, 0-2, 1-3, 2-4, 3-4, 4-5, starting from vertex 0 and always…
- Problem: What does the following print? python print(sorted(['b', 'B', 'a', 'A']))
- Problem: Selection sort is run on [4, 3, 2, 1] in the usual way (for each position, find the minimum of the unsorted suffix and swap it…
- Problem: A Rule 90 cellular automaton on an infinite line starts with a single live cell. A cell's next state is 1 exactly when its two…
- Problem: A lucky 4-digit ticket has the sum of its first two digits equal to the sum of its last two digits. Each ticket number runs from…