Data Structures & AlgorithmsHardFlipkart/Uber OA · placement
Lines of heights [9, 5, 3, 2, 4, 9, 1, 2, 9] stand at x = 0, 1, …, 8. Two pointers find the pair of lines that, with the x-axis, holds the most water (area = min(h[i], h[j]) × (j − i)). What is that maximum area?
- A. 72
- B. 71
- C. 37
- D. 8
Correct answer: A. 72
Start with the widest pair and always move the pointer at the shorter line inward (the taller one cannot do better with a narrower width). The best area is 72.
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
- How many different pop sequences are possible when 6 distinct items are pushed onto a stack in a fixed order, with pops allowed at any time?
- Count zero-sum contiguous subarrays with a prefix-sum frequency map. What is printed? python from collections import defaultdict a = [1…
- Daily prices are [26, 31, 28, 30, 24, 30, 18, 37, 13]. What is the maximum profit with at most ONE buy and one later sell, and with…
- Floyd's cycle detection on a list whose last node links back into the list. What does this print (meeting value, cycle-start value, cycle…
- One Lomuto partition (pivot = LAST element; i marks the end of the 'less than pivot' region; when a[j] < pivot, increment i and swap a[i]…
- 9 people stand in a circle numbered 1 to 9. Counting starts at person 1, and every 3rd person is removed (counting continues from the next…