Data Structures & AlgorithmsHardTCS NQT · Accenture
Problem: A grid of 3 rows and 3 columns is filled with the numbers 1 to 9 row by row. A "line" is a complete row, column or main diagonal. How many lines have a sum greater than 14?
- A. 4
- B. 6
- C. 8
- D. 5
Correct answer: B. 6
Line sums: rows 6, 15, 24; columns 12, 15, 18; diagonals 15, 15, so six exceed 14. Ignoring the diagonals gives 4, counting every line gives 8, and using only one diagonal gives 5.
More Coding Interview Problems questions
- Problem: What is the number of lattice points (x, y) with x, y ≥ 0 and x + y ≤ 5?
- Problem: The array [5, 1, 4, 2, 3] is sorted by repeatedly swapping adjacent elements that are out of order (bubble sort). How many passes…
- Problem: The Hamming weight (number of 1-bits) of each integer from 0 to 15 is summed. What is the total?
- Problem: A set of letters {A, B, C, D, E} is arranged in a row. How many arrangements have A immediately to the left of B?
- Problem: The number of ways to split a line of 6 people into 2 groups of 3 (groups are distinguishable by their first member, so each…
- Problem: The string "racecar" is compared with its reverse position by position. How many positions have matching characters?