Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many elements of [1, 5, 2, 8, 3, 9, 4] are strict local maxima (strictly greater than both neighbours; the two end elements are excluded)?
- A. 4
- B. 3
- C. {C-1}
- D. 5
Correct answer: B. 3
Check each interior element against both neighbours; the values 5, 8 and 9 qualify. Including the ends would wrongly add 1 or 4.
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 sorted linked list is [1, 1, 2, 3, 3, 3, 4]. All duplicate nodes are removed so that each value appears once. What is the sum of the…
- The nodes of the list 1, 2, 3, 4, 5, 6, 7, 8 are rearranged into all odd-position nodes followed by all even-position nodes (1-based…
- How many contiguous subarrays of [1, 2, 3, 4, 5, 6, 7] contain exactly 2 odd numbers?
- How many index pairs i < j in [1, 2, 3, 4, 5] have a[i] XOR a[j] equal to a power of two?
- How many index triples i < j < k in the array [1, 2, 3, 4, 5, 6] have a[i] + a[j] + a[k] = 10?
- How many values in [4, 4, 5, 6, 6, 7, 8] occur exactly once in the array?