Given an array of integers representing daily stock prices, determine the length of the longest bull-run and bear-run sequence, defined as an increasing sequence of prices followed by a decreasing sequence of prices.
Explanation: Step-by-step: with input [12, 15, 18, 20, 18, 15, 12], we first find the longest increasing sequence [12, 15, 18] with length 3. Then, we find the longest decreasing sequence [18, 15, 12] with length 3. The longest bull-run and bear-run sequence is [12, 15, 18] and [18, 15, 12] respectively with length 3.
Explanation: Step-by-step: with input [5, 7, 9, 10, 12, 10, 8, 6], we first find the longest increasing sequence [5, 7, 9, 10] with length 4. Then, we find the longest decreasing sequence [12, 10, 8, 6] with length 4. The longest bull-run and bear-run sequence is [5, 7, 9, 10] and [12, 10, 8, 6] respectively with length 4 and 4 respectively.
Master coding challenges related to Arrays and solve the [Backup] Financial Trends problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak