Data Structures & AlgorithmsHardFlipkart/Uber OA · placement
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 UNLIMITED non-overlapping transactions?
- A. 32 and 32
- B. 24 and 32
- C. 19 and 19
- D. 19 and 32
Correct answer: D. 19 and 32
One transaction: track the minimum price so far and the best difference (19) — max − min fails when the minimum comes after the maximum. Unlimited: add every positive day-to-day rise (32).
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
- 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…
- A hash-map two-sum returns the first index pair (i, j), i < j, found while scanning left to right. What is printed? python def twosum(a…
- A sorted array was rotated to give [29, 47, 50, 57, 60, 61, 75, 4, 5, 8, 13]. Binary search finds the index of the minimum: while lo < hi…
- Lines of heights [6, 9, 5, 6, 8, 1, 8, 3, 5] stand at x = 0, 1, …, 8. Two pointers find the pair of lines that, with the x-axis, holds the…