Bird
Raised Fist0

Given the following partial state of the up and down arrays after processing the input array: up = [1, 2, 2, 3, 3] down = [1, 1, 3, 3, 4] What could be the original input array?

hard🔄 Reverse Engineer Q9 of Q15
Greedy Algorithms - Wiggle Subsequence
Given the following partial state of the up and down arrays after processing the input array: up = [1, 2, 2, 3, 3] down = [1, 1, 3, 3, 4] What could be the original input array?
A[1, 7, 4, 9, 2]
B[1, 2, 2, 3, 3]
C[5, 5, 5, 5, 5]
D[1, 3, 2, 4, 3]
Step-by-Step Solution
Solution:
  1. Step 1: Understand up/down arrays meaning

    up[i] = length of longest wiggle subsequence ending with an upward wiggle at i; down[i] similarly for downward.
  2. Step 2: Match pattern to input

    Values suggest alternating ups and downs with lengths matching known example [1,7,4,9,2].
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Only [1, 7, 4, 9, 2] matches wiggle subsequence lengths given [OK]
Quick Trick: Match up/down arrays to known wiggle subsequence patterns [OK]
Common Mistakes:
MISTAKES
  • Confusing arrays with input values
  • Ignoring meaning of up/down arrays
Trap Explanation:
PITFALL
  • Candidates often fail to reverse engineer from DP arrays to input sequence.
Interviewer Note:
CONTEXT
  • Tests deep understanding of DP state and ability to reason backwards.
Master "Wiggle Subsequence" in Greedy Algorithms

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Greedy Algorithms Quizzes