Data Structures & AlgorithmsHard
Why is the OR of a subarray always at least the maximum element of that subarray?
- A. OR is always smaller than the smallest element.
- B. OR equals the sum of the subarray.
- C. OR keeps every set bit of each operand, so the result is at least each operand, including the largest.
- D. OR depends only on the length.
Correct answer: C. OR keeps every set bit of each operand, so the result is at least each operand, including the largest.
Each operand's bits survive in the OR, so the result is never smaller than any single operand. The maximum is therefore a lower bound for the OR.
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
- When counting triangles from sorted stick lengths with a two-pointer scan, why does fixing the largest side k and moving the pointers i <…
- Why is the inequality test for a non-degenerate triangle with sorted sides written as ai + aj > ak for the largest side ak?
- 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?