ProgrammingHardTCS NQT · Infosys
A 3 x 3 grid holds 1 to 9 row by row, so row 0 is 1 2 3, row 1 is 4 5 6 and row 2 is 7 8 9. What is the sum of the 2 x 2 block with rows 1 to 2 and columns 1 to 2?
- A. 28
- B. 24
- C. 30
- D. 26
Correct answer: A. 28
The block holds 5, 6, 8 and 9, which sum to 28. A 2D prefix sum answers any such block in O(1) after O(n*m) preprocessing.
More C Programming questions
- In the sorted array {1, 2, 4, 6, 8, 9}, how many unordered pairs of distinct elements sum to 17?
- What is the largest sum of any three consecutive elements of {2, 1, 5, 1, 3, 2}?
- The sorted array is {1, 3, 6, 6, 8}. What is the index of the first occurrence of 6?
- How many integers in the range 0 to 15 have an even number of 1 bits in binary?
- How many 1 bits are set in 2^20 - 1 (a 32-bit unsigned value)?
- uint8t a = 16; a = a a; What is a?