Data Structures & AlgorithmsModerateICPC regional · GATE CS
Problem: The matrix [[2,0],[0,3]] is raised to the power 4 (matrix power). What is the sum of all entries of the result?
- A. 625
- B. 97
- C. 20
- D. 1296
Correct answer: B. 97
A diagonal matrix powers entry-wise on its diagonal: diag(16, 81), whose entries sum to 97. (2 + 3)⁴ gives 625, multiplying by 4 gives 20, and 6⁴ = 1296 is the determinant's power.
More Coding Interview Problems questions
- Problem: A word is "statistics". How many distinct letters appear at least twice in it?
- Problem: A sorted array [2, 3, 5, 7, 11, 13, 17, 19] is searched for 11 using binary search with mid = (lo + hi) // 2 over the inclusive…
- Problem: Consider the string "xyzzyzyx". How many distinct substrings of length 2 are there?
- Problem: The array [1, 4, 6, 3, 8, 2] is processed by a single pass that tracks the maximum so far. How many elements are records…
- Problem: A set of 10 people is divided into 5 pairs. How many distinct ways are there to form these pairs (unordered pairs, unordered…
- Problem: In the array [5, 8, 3, 7, 2], find the second-largest element.