Data Structures & AlgorithmsHardAmazon · Microsoft coding round
For each element of the array [6, 2, 5, 4, 7, 3, 1, 8, 2] find the next greater element to its right (the value -1 if none exists). What is the sum of all these values?
- A. 48
- B. 50
- C. 32
- D. 44
Correct answer: A. 48
The next greater values are 7, 5, 7, 7, 8, 8, 8, -1, -1, which sum to 48. Counting 'none' as 0 gives 50, and scanning to the left instead gives 32.
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 hash table of size 11 uses h(k) = k mod 11 with linear probing. Keys 5, 16, 27 and 38 are inserted in this order, and then key 16 is…
- For the array [1, 3, -1, -3, 5, 3, 6, 7, 2, 9], consider every window of 4 consecutive elements. The sum of the maximum of each window is:
- A circular queue uses an array of size 5 with the convention that front is the index of the next element to dequeue, rear is the index of…
- The integers 1, 2, 3, 4, 5, 6 are pushed onto an initially empty stack in this order; pops may happen at any time, and the 6 popped values…
- A hash table of size 11 uses double hashing: the probe sequence for key k is (k mod 11 + i · (7 − (k mod 7))) mod 11 for i = 0, 1, 2…
- A hash table of size 7 uses h(k) = k mod 7 with linear probing. A delete leaves a tombstone, an insert goes into the first empty or…