Given an array of signal strengths from a distant planet, determine the length of the longest subsequence where the signal strengths alternate between increasing and decreasing order, helping astronomers identify stable communication windows.
Explanation: Step-by-step: Given the input [5, 8, 6, 9, 5], we can see that the longest subsequence where the signal strengths alternate between increasing and decreasing order is [5, 8, 6] or [6, 9, 5]. Both subsequences have a length of 3, but we need to find the longest valid subsequence. In this case, the longest valid subsequence is [5, 8, 6] or [6, 9, 5] with length 3.
Explanation: Step-by-step: Given the input [1, 3, 2, 4], we can see that the longest subsequence where the signal strengths alternate between increasing and decreasing order is [1, 3, 2, 4]. This subsequence has a length of 4, and it is valid. Therefore, the longest valid subsequence is [1, 3, 2, 4] with length 4.
Master coding challenges related to Arrays and solve the [Backup] Galactic Signal Patterns problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak