Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
What is the sum of the minimum over all contiguous subarrays of [3, 1, 2, 4] that have length at least 2?
- A. 8
- B. 7
- C. 9
- D. 11
Correct answer: B. 7
Subarrays of length at least 2 are the pairs, triples and the full array; their minima are 1, 1, 1, 2, 1, 1 (not all of them). Summing these gives the total.
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
- In a grid, 2 marks a rotten orange, 1 a fresh one and 0 an empty cell. Each minute every fresh orange adjacent (4 directions) to a rotten…
- The 0/1 grid [[1,1,0],[0,1,0],[1,0,1]] is given. Two 1-cells belong to the same island if they are adjacent horizontally or vertically…
- Two numbers are stored as linked lists of digits, least significant digit first: 9 -> 9 -> 9 and 1. Their sum is added digit by digit with…
- How many index pairs i < j in [3, 4, 2, 6, 1, 2, 12, 1] have a[i] a[j] = 12?
- How many distinct strings of length 3 are palindromes that occur as subsequences of abcab (of the form x y x with y different from x)?
- What is the length of the longest palindromic subsequence of the string leetcode?