Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
How many index triples i < j < k in [1, 2, 3, 4, 5, 6] satisfy a[i] + a[k] = 2 * a[j]?
- A. 4
- B. 20
- C. 6
- D. 2
Correct answer: C. 6
a[i] + a[k] = 2a[j] means the three values form an arithmetic progression: difference 1 gives (1,2,3), (2,3,4), (3,4,5), (4,5,6), difference 2 gives (1,3,5), (2,4,6), so 6. Only difference 1 gives 4, only difference 2 gives 2, and 20 counts all triples.
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 area of the largest rectangle under the histogram [3, 1, 3, 2, 2]?
- How many distinct XOR values arise from index pairs i < j of [1, 2, 3, 4]?
- How many non-empty prefixes of "abacaba" are palindromes?
- What is the minimum number of single-character flips needed to turn the binary string "10100101" into a string of the form 0...01...1 (all…
- For [1, -2, 3, 4, -1, 5, -6, 2], you may delete at most one element before taking a maximum sum over non-empty contiguous subarrays. What…
- What is the sum of i j over all pairs 1 <= i < j <= 6?