Data Structures & AlgorithmsModerateTCS NQT · logic
Problem: A player picks a number from 1 to 10 and the other player must guess it by yes/no questions. The minimum worst-case number of questions needed is what?
- A. 4
- B. 3
- C. 5
- D. 10
Correct answer: A. 4
Each yes/no question halves the candidate set, and 2^3 = 8 < 10 <= 16 = 2^4, so 4 questions are needed in the worst case. A binary search over 10 values takes ceil(log2 10) = 4 steps.
More Coding Interview Problems questions
- Problem: What is the complexity of computing all prefix XOR values of an array of n = 10^6 integers and then answering q = 10^6 range-XOR…
- Problem: Consider a DP over subsets for assigning n jobs to n workers (cost matrix given), with state = mask of assigned jobs and…
- Problem: A string of length n is built using the operation 'append the reverse of the current string'. Starting with 'a', the length after…
- Problem: Which statement about Dijkstra's algorithm using a binary heap with lazy deletion (pushing duplicate entries and skipping stale…
- Problem: What does the following print? python x = 5 print(x << 3 | x >> 1, x & 6, x ^ 3)
- Problem: For the string 'mississippi', what is the number of distinct substrings of length 2 that occur at least twice? Run the code…