Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
On a 3 by 3 grid, how many unordered pairs of distinct cells share a row or a column?
- A. 19
- B. 36
- C. 30
- D. 18
Correct answer: D. 18
Each of the 3 rows has C(3,2) = 3 pairs, giving 9, and each of the 3 columns gives another 9, for 18 in total. The count of all pairs (36) is the trap.
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
- What is the length of the longest run of equal consecutive values in [5, 5, 5, 6, 6, 5, 5, 5, 5]?
- How many length-2 substrings of "abbaabab" are either "ab" or "ba"?
- From task sizes [4, 5, 6, 3], what is the largest number of tasks you can keep so that their total size is at most 10?
- How many subsets (including the empty set, but counting each subset once) of [1, 2, 3, 4] have element sum equal to 5?
- Convert (a+b)c/(d-e) to postfix with the shunting-yard algorithm (+ and - lowest, then and /, all left-associative). What is the postfix…
- Evaluate the postfix expression 2 3 1 + 9 -. What is the result?