Which of the following problems CANNOT be solved efficiently using the wiggle subsequence greedy pattern?
easy🔍 Pattern Recognition Q2 of Q15
Greedy Algorithms - Wiggle Subsequence
Which of the following problems CANNOT be solved efficiently using the wiggle subsequence greedy pattern?
AFind the maximum length subsequence where differences alternate in sign
BFind the longest subsequence with strictly alternating positive and negative differences
CFind the length of the longest wiggle subsequence in an integer array
DFind the longest contiguous subarray with alternating signs in differences
Step-by-Step Solution
Solution:
Step 1: Analyze each problem
Options A, C, and D describe wiggle subsequence problems solvable by greedy. Finding the longest contiguous subarray with alternating signs in differences asks for contiguous subarray, which is different.
Step 2: Identify anti-pattern
Longest contiguous alternating subarray requires sliding window or DP, not wiggle subsequence greedy pattern.
Final Answer:
Option D -> Option D
Quick Check:
Only contiguous alternating subarray is not solved by wiggle subsequence pattern [OK]