Data Structures & AlgorithmsVery hard
Why is the inequality test for a non-degenerate triangle with sorted sides written as a_i + a_j > a_k for the largest side a_k?
- A. The two shorter sides must together exceed the longest side; if this holds, the other two inequalities follow automatically.
- B. All three pairs of sides must sum to more than the third.
- C. The longest side must equal the sum of the other two.
- D. Only the shortest side matters.
Correct answer: A. The two shorter sides must together exceed the longest side; if this holds, the other two inequalities follow automatically.
With sides sorted, a_i + a_k > a_j and a_j + a_k > a_i hold automatically once a_i + a_j > a_k, so one comparison suffices. Equality would give a degenerate triangle with zero area.
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
- To count subarrays with sum divisible by m, why does the equal-residue method fail for a subarray count that depends on the MAXIMUM element?
- In the 'longest window with equal numbers of high and low values' problem, what turns the condition into a standard prefix-sum problem?
- When two consecutive windows of length 3 are compared, why does equal sums reduce to a single element comparison?
- Why does a pair (i<j) with A[i] AND A[j] = 0 require disjoint sets of set bits?
- Among pairs with A[i] ≠ A[j] and A[i] XOR A[j] = 0, how many exist?
- Why can the number of distinct OR values over all subarrays of an array be small even for long arrays?