Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
For [3, 1, 4, 2], split into a non-empty prefix and a non-empty suffix. For each split compute (minimum of prefix) times (maximum of suffix), then take the largest value. What is it?
- A. 13
- B. 12
- C. 10
- D. 4
Correct answer: B. 12
Try each split point: prefix minima and suffix maxima give 3 * 4 = 12, 1 * 4 = 4 and 1 * 2 = 2. The best is 12 with the split after the first element.
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 split point is an index i (1 ≤ i ≤ n−1) that divides [1, 2, 3, 3, 2, 1, 4, 2] into a left part a[0..i−1] and a right part a[i..n−1] with…
- What is the length of the longest contiguous subarray of [5, 3, -2, 8, -4, 6, 1, 7] whose sum is divisible by 5 (the empty sum 0 counts as…
- How many DISTINCT values can the sum of a subset of [1, 2, 4, 8, 3] take? The empty subset (sum 0) is included.
- How many subsets of [2, 5, 3, 7, 1] (chosen by position, empty subset included) have a total sum at most 8?
- How many permutations of 1 to 6 have NO fixed point (that is, p[i] ≠ i for every position i)?
- How many strings of length 6 over {a, b} have NO position i with s[i] = s[i+2] (for every valid i)?