Given a list of daily temperature readings and a trend pattern, find the longest subsequence of temperatures that matches the given pattern, where 'A' represents an increase in temperature and 'D' represents a decrease.
Explanation: Step-by-step: We start with the input [20, 19, 22, 25] and pattern 'DAA'. We find a decrease from 20 to 19 (D), then an increase from 19 to 22 (A), and finally an increase from 22 to 25 (A). However, there is no temperature decrease from 22 to 25, so we cannot match the pattern 'DAA' with the input. Therefore, the longest subsequence of temperatures that matches the given pattern is 1.
Explanation: Step-by-step: We start with the input [27, 29, 32, 30] and pattern 'AAD'. We find an increase from 27 to 29 (A), then a decrease from 29 to 32 (D), and finally a decrease from 32 to 30 (D). However, there is no temperature increase from 30 to 32, so we cannot match the pattern 'AAD' with the input. Therefore, the longest subsequence of temperatures that matches the given pattern is 2.
Master coding challenges related to Arrays and solve the [Backup] Temperature Trend Analyzer problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak