Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: Find the smallest positive integer x such that floor(x/2) + x is at least 50.
- A. 33
- B. 34
- C. 17
- D. 50
Correct answer: B. 34
f(33) = 16 + 33 = 49 < 50 and f(34) = 17 + 34 = 51 ≥ 50, so x = 34. Returning the last failing x gives 33, 17 is floor(34/2), and 50 ignores the floor(x/2) term.
More Coding Interview Problems questions
- Problem: A set of jobs has deadlines and profits: (deadline 1, profit 20), (deadline 2, profit 40), (deadline 2, profit 30), (deadline 3…
- Problem: The insertion sort is applied to [3, 1, 2]. Count the total number of element moves (each shift of an element one place to the…
- Problem: Heap-indexed binary tree with 10 nodes (node i has children 2i and 2i+1 when ≤ 10). How many nodes lie at depth 2 (root at depth…
- Problem: In the sorted array [−3, −1, 0, 1, 2, 3], how many pairs of distinct positions (i < j) have a sum of exactly 0?
- Problem: What is C(10, 3) modulo 7?
- Problem: How many prime numbers lie strictly between 100 and 150?