Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: The string "xyzxyzxyz" is split into 3 equal blocks of length 3. The blocks are compared: how many pairs of blocks (i < j) are equal as strings?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
All three blocks equal 'xyz', so every one of the three index pairs matches. Counting distinct block contents (one) gives a different quantity than the pair count.
More Coding Interview Problems questions
- Problem: From the list of integers [10, 15, 20, 25, 30], remove the elements that are divisible by 4 or by 6 (the rest remain in order)…
- Problem: The number 1729 is written in base 10. What is the sum of its digits in base 12, given as the digit sum of 1729 written in base 12?
- Problem: A sorted list has values 3, 7, 7, 9, 12, 12, 12, 15. How many distinct values lie within the range [7, 12] inclusive?
- Problem: On a 3×3 grid, each cell is labelled with its row times column (1-indexed). The number of cells whose label is a perfect square…
- Problem: How many integers in [1, 100] have exactly 3 divisors? Run the code. python print(sum(1 for x in range(1, 101) if sum(1 for d in…
- Problem: What is the sum of the digits of 3^20? Run the code. python print(sum(int(c) for c in str(3 20))) What is printed?