Given an integer array nums, return the length of the longest wiggle subsequence. A wiggle sequence is defined as a sequence where the differences between consecutive numbers strictly alternate between positive and negative. Implement an efficient algorithm to determine this length.
int wiggleMaxLength(vector<int>& nums) {
int n = nums.size();
if (n == 0) return 0;
int up = 1, down = 1;
for (int i = 1; i < n; i++) {
if (nums[i] > nums[i - 1]) {
up = down + 1;
} else if (nums[i] < nums[i - 1]) {
down = up + 1;
}
}
return max(up, down);
}

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What is recursion?