Data Structures & AlgorithmsVery hardCodeforces Div2 C · TCS NQT
Choose two positions i < j with j − i ≥ 3 in [5, -4, 3, 8, -6, 2, 7]. What is the largest possible product a[i] · a[j]?
- A. 56
- B. 62
- C. -48
- D. 57
Correct answer: A. 56
For the two-large-negatives case the best product can come from two negatives far apart; fix j and track the most positive and most negative values among indices at least d behind. Restricting to adjacent positions, or lowering the required distance, changes the answer.
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 minimum number of characters you must delete from "aaabbbbcccccdd" so that no three equal letters are consecutive?
- How many non-empty subsets of {1, 2, ..., 8} have a sum divisible by 4?
- How many contiguous subarrays of [3, 1, 4, 1, 5, 2] have their FIRST element as their maximum (ties count as maximum)?
- What is the length of the longest subsequence (any positions, keeping order) of [2, 3, 5, 1, 4] whose product is at most 12?
- How many non-empty subsets of [1, 2, 3, 4, 5, 6, 7] (chosen by position) have a sum that is a perfect square?
- How many non-empty subsets of [2, 4, 6, 8, 10, 12, 3] (chosen by position) have a sum of exactly 25?