Data Structures & AlgorithmsHardLeetCode-style · TCS NQT
Daily prices are [1, 2, 3, 0, 2, 5, 1, 6]. You may buy or sell one share per day, hold at most one share, and after SELLING you must wait one full day before buying again. What is the maximum profit?
- A. 8
- B. 12
- C. 6
- D. 9
Correct answer: A. 8
Keep three states per day: holding a share, just sold (cooldown next day), and free to buy. The cooldown rules out the plain 'sum of rises' answer, and the three-state DP handles it exactly.
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 maximum sum of a non-empty contiguous subarray of the CIRCULAR array [5, -3, 5, -2, 7, -6, 4]? A subarray may wrap from the…
- Three fair six-faced dice are rolled. How many ordered outcomes (d1, d2, d3) have a total of exactly 10?
- How many arrays of length 4 with entries from {1, 2, 3} have no two adjacent entries equal?
- Grid rows (top to bottom): '....', '.#..', '...#', '#...', '....'. '#' is an obstacle, '.' is free. Starting at the top-left cell, you…
- A triangle of numbers has rows [9], [7, 6], [9, 7, 4], [6, 1, 5, 3], [6, 9, 2, 4, 5]. Starting at the top, each step goes to one of the…
- How many non-empty contiguous subarrays of [-4, 2, -7, 5, -1, 3, -2, 6] have a sum divisible by 3 (the sum 0 counts as divisible)?