Data Structures & AlgorithmsHardGATE CS · TCS NQT
What is the sum of the minimum of every contiguous window of length 2 in the array [3, 1, 4, 1, 5, 9, 2, 6]?
- A. 14
- B. 10
- C. 13
- D. 15
Correct answer: C. 13
Each window of length 2 contributes its smaller element; the window minimum of adjacent pairs is min(a[i], a[i+1]). Summing the larger values instead is the common slip.
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
- A singly linked list contains the people 1 to 12 in a circle. Starting from person 1, every 4th person is removed (the count starts at 1)…
- How many contiguous subarrays of [3, 4, -7, 1, 2, -6] have a sum of exactly zero?
- In the array [1, 4, 6, 8, 13], the minimum absolute difference between two distinct elements is d. How many index pairs i < j have |a[i]…
- How many strings of length 4 over the alphabet {a, b} contain the letter a somewhere before a b (that is, contain 'a' followed later by…
- What is the edit distance (Levenshtein distance with insertion, deletion and substitution each costing 1) between intention and execution?
- What is the length of the longest common subsequence of AGGTAB and GXTXAYB (letters need not be contiguous)?