Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B
How many index pairs i < j in [1, 2, 3, 4, 5, 6] satisfy that a[i] times a[j] equals a[i] plus a[j]?
- A. 1
- B. 2
- C. 4
- D. 0
Correct answer: D. 0
x*y = x+y is equivalent to (x-1)(y-1) = 1, which only holds for x = y = 2 or x = y = 0. Since the values are distinct, the answer is found by algebra, not by search.
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
- Which data structure supports inserting values and reporting the k-th smallest value in O(log n) time each?
- Which algorithm counts occurrences of a pattern p inside a text t in O(|t| + |p|) time?
- Which algorithm finds the longest palindromic substring of a string in linear time?
- Which technique detects whether an array contains a non-empty subarray with sum zero in O(n) expected time?
- An array of 200000 integers may contain negative values, and you must count its contiguous subarrays whose sum equals K in near-linear…
- For a string of length 10^6 and a pattern of 20 letters, you need the shortest substring containing every pattern letter with…