Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
How many index triples i < j < k in [2, 3, 4, 5, 7, 10] can be the three sides of a non-degenerate triangle (sum of the two smaller sides strictly greater than the largest)?
- A. 8
- B. 6
- C. 7
- D. 10
Correct answer: C. 7
After sorting, fix the largest side k and use two pointers over the smaller sides: if a[i] + a[j] > a[k], all indices between i and j-1 also work. The strict inequality matters for equal sums.
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
- How many index pairs i < j in [3, 5, 6, 8, 1] satisfy a[i] + a[j] > a[i] XOR a[j]?
- What is the smallest positive integer divisor d such that the sum of ceil(x / d) over [1, 2, 5, 9] is at most 6?
- Sort [6, 3, 4, 1, 2, 5] so that all even numbers come first in increasing order, then all odd numbers in increasing order, using adjacent…
- Each operation doubles one element of [4, 8, 16, 2]. What is the minimum number of operations needed to make all four elements equal?
- For the positive array [2, 1, 3, 4, 1], how many contiguous subarrays have a sum at most 5?
- How many contiguous subarrays of [1, 2, 1, 3, 4, 2, 3] contain exactly 3 distinct values?