Skip to content

Conversation

Siddhram
Copy link

This PR introduces a complete and well-documented implementation of the Wiggle Subsequence problem in R.

Overview

The implementation provides an O(n)-time, O(1)-space dynamic programming solution using a classic rolling-state approach. It tracks the longest subsequence ending with positive and negative differences and includes clear headers, intuition, complexity notes, and runnable examples.

Features

  • Rolling-state DP:
    • up = longest wiggle subsequence ending with positive difference
    • down = longest wiggle subsequence ending with negative difference
  • Single pass; O(1) extra space
  • Handles edge cases: empty array, single element, monotonic arrays, duplicates
  • Consistent headers, comments, and demonstration section

Complexity

  • Time Complexity: O(n)
  • Space Complexity: O(1)

Directory

  • Updated DIRECTORY.md to include “Wiggle Subsequence” under Dynamic Programming

Demonstration

Run the script to execute built-in examples:

From command line:

Rscript "R/dynamic_programming/wiggle_subsequence.r"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant