Data Structures & AlgorithmsHardTCS NQT · Accenture
In the array [1, 4, 2, 6, 5, 7], a value is a record if it is strictly greater than every value before it. What is the sum of all record values?
- A. 19
- B. 20
- C. 22
- D. 18
Correct answer: D. 18
Records are 1, 4, 6 and 7; the values 2 and 5 are not records because they are below an earlier maximum.
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
- What is the maximum nesting depth of the parentheses in the string a(b(c)d)(e(f(g))) ?
- 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…
- 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?