Data Structures & AlgorithmsHard
For 3 9 1 7 2 8 4, split the array into a non-empty left part and a non-empty right part at some position p. What is the LARGEST possible value of (maximum of the left part) − (minimum of the right part)?
- A. 7
- B. 8
- C. 2
- D. 9
Correct answer: B. 8
For each split, the left maximum is a running prefix maximum and the right minimum is a suffix minimum, both computable in one pass. Using the global spread, subtracting one, or taking the worst split answers different questions.
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
- Using only swaps of ADJACENT characters, what is the minimum number of swaps needed to move ALL letters 'x' of "bxaxxbx" to the very front…
- From the digit string "53412", delete EXACTLY two characters (the remaining characters keep their order). What is the lexicographically…
- How many DISTINCT non-empty strings can be formed as subsequences (characters taken in order, not necessarily adjacent) of "abab"?
- Arrange the numbers 3 30 34 5 9 in some order and concatenate their decimal digits. What is the LARGEST number that can be produced?
- From 4 9 1 7 3 8 2, choose positions so that no two CHOSEN positions are adjacent in the array. What is the maximum possible sum of the…
- How many index pairs i < j in 2 7 4 9 6 3 8 have an ODD sum A[i] + A[j] while also satisfying A[i] < A[j]?