Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many contiguous subarrays of [1, 2, 4, 3, 6] have a bitwise OR equal to exactly 7?
- A. 7
- B. 8
- C. 10
- D. 2
Correct answer: B. 8
The OR only grows as a subarray extends, so a brute force over start and end indices counts exactly the subarrays whose OR equals 7. Targeting 6 instead is a different count.
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 distinct non-empty substrings does the string "abacaba" have?
- In the string "ababababa", how many times does "aba" occur, counting overlapping occurrences?
- For the string "aabaaab", what is the last value of the KMP prefix-function (the length of the longest proper prefix that is also a suffix…
- What is the smallest period p (1 <= p < n) of the string "abcabcabca" such that s[i] = s[i + p] for all valid i?
- Using the standard convention z[0] = 0, what is the sum of the Z-function values z[1] through z[6] of the string "aaabaab"?
- What is the area of the largest rectangle that fits in the histogram with bar heights [2, 1, 5, 6, 2, 3]?