Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
How many contiguous subarrays of [3, 1, 2, 1, 4] have their minimum equal to their first element?
- A. 15
- B. 9
- C. 7
- D. 5
Correct answer: B. 9
For each start, the valid ends run until a strictly smaller element appears (ties are fine, since the first element only needs to be ≤ the rest): 1 + 4 + 1 + 2 + 1 = 9. Requiring it to be strictly smaller gives 7, 15 counts all subarrays and 5 only singletons.
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 entries of [1, 6, 8, 12, 16, 33, 64, 0] are powers of two (with 1 counted)?
- What is the length of the longest contiguous subarray of [0, 1, 0, 0, 1, 1, 0, 1] containing equal numbers of 0s and 1s?
- How many ordered pairs of distinct positions (i, j) in [2, 3, 4, 6, 12] satisfy a[j] divisible by a[i]?
- In how many ways can 12 be written as a sum of distinct positive odd integers (order does not matter)?
- How many integers from 1 to 60 inclusive have exactly four positive divisors?
- For [4, 2, 5, 3, 1], each index i gets the index of its next strictly smaller element to the right (or -1 if none). What is the sum of…