Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: What is the smallest positive integer x such that 1 + 2 + … + x is at least 100?
- A. 13
- B. 14
- C. 10
- D. 105
Correct answer: B. 14
T(13) = 91 < 100 and T(14) = 105 ≥ 100, so x = 14. Returning the last x below the target gives 13, using √100 gives 10, and 105 is the triangular number itself, not x.
More Coding Interview Problems questions
- Problem: How many composite numbers lie in the range 2 to 50 (inclusive)?
- Problem: How many integers x with 0 ≤ x ≤ 99 satisfy x³ ≡ x (mod 7)?
- Problem: Daily temperatures are [73, 74, 75, 71, 69, 72, 76, 73]. For each day, the wait is the number of days until a strictly warmer day…
- Problem: In the binary array [1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1] at most 2 zeros may be flipped to 1. What is the length of the longest run…
- Problem: Starting from the empty set, a process inserts the numbers 5, 3, 8, 1, 4, 7 into a binary search tree, and then deletes nothing…
- Problem: The array [4, 2, 5, 1, 3] is turned into a max-heap by sift-down from the last parent to the root (standard heapify, 0-indexed)…