Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
What is the maximum area of water a container can hold between two bars of heights [1, 8, 6, 2, 5, 4, 8, 3, 7] (area = min(height) times distance between indices)?
- A. 42
- B. 28
- C. 49
- D. 64
Correct answer: C. 49
Two pointers move the shorter side inward, because the shorter line limits the area and no better partner exists for it. The optimum here is between heights 8 and 7 at distance 7.
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 length of the longest palindromic substring of "forgeeksskeegfor"?
- Which string is the lexicographically smallest rotation of "bcabca"?
- With coin denominations 1, 3 and 4, what is the minimum number of coins needed to make the amount 6?
- What is the maximum number of pairwise non-overlapping intervals (an interval [s, f) may touch the next one at f = s) chosen from…
- A railway station receives trains at times 900, 940, 950, 1100, 1500, 1800 and each train leaves at 910, 1200, 1120, 1130, 1900, 2000…
- For the array [3, 1, 4, 1, 5, 9, 2, 6], how many subarrays have a product that is a multiple of 6?