Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT
What is the maximum product of THREE distinct elements of [-10, -3, 1, 5, 2, -8, 4] (chosen by position)?
- A. 40
- B. 400
- C. 360
- D. 125
Correct answer: B. 400
Sorting gives two candidates: the three largest, or the two most negative times the largest. Taking only the three largest misses the case where two large negatives multiply to a large positive.
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
- The substitutions-only distance (Hamming distance) between "karolin" and "kathrin" counts positions where the letters differ. What is that…
- What is the length of the longest repeating subsequence of "aabebcdd"? It is a subsequence that appears at least twice, where the two…
- Four houses are painted with one of 3 colours. Painting house i with colour c costs cost[i][c] = [[17, 2, 17], [16, 16, 5], [14, 3, 19]…
- Events are given as (start day, end day) inclusive: [(1, 2), (2, 3), (3, 4), (1, 2), (3, 5)]. You may attend at most one event per day…
- Split "ababcbacadefegdehijhklij" into the maximum number of contiguous pieces so that each letter appears in at most one piece. What is…
- Unit-time tasks have deadlines [1, 2, 2, 3, 3, 3, 5, 6] (a task must finish by its deadline, and only one task runs at a time from time…