Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional
Each row and each column of a 4 × 4 matrix is sorted in increasing order: [[1, 5, 9, 12], [2, 6, 10, 15], [3, 7, 11, 16], [4, 8, 13, 20]]. What is the 7th smallest value in the whole matrix?
- A. 10
- B. 8
- C. 7
- D. 20
Correct answer: C. 7
Binary search on a value x, counting entries ≤ x with a staircase walk from the bottom-left corner: the count first reaches 7 at x = 7 (1, 2, 3, 4, 5, 6, 7). Reading row by row gives 10, the 8th smallest is 8, and 20 is the largest entry.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Choose a subsequence of [3, 8, 1, 9, 2, 7] (keeping order, possibly any length ≥ 1). Its alternating sum is the first chosen element minus…
- What is the length of the longest contiguous subarray of [4, 7, 2, 9, 6, 3, 8, 10, 5] in which the parity of consecutive elements…
- Choose a subsequence of [5, -2, 7, 1, -3, 6, 4] in which any two consecutive CHOSEN indices differ by at most 2 positions (by index). A…
- How many ways can "abcabcdaab" be cut into a non-empty left part and a non-empty right part so that the two parts contain the same number…
- How many DISTINCT values appear among the sums of all non-empty contiguous subarrays of [2, -1, 3, 0, -2, 4]?
- How many unordered pairs of positions (i < j) in "abababcabab" have the same 2-letter substring starting there (s[i:i+2] == s[j:j+2])?