```
public int wiggleMaxLength(int[] a) {
if(a.length<2) return a.length;
int prev = a[0], maxLen=1
boolean increasing = a[1]>a[0]; // denoting if we are expecting increased relative to prev
for(int i=1; i<a.length; i++){
if ( (increasing && (a[i] >prev)) || (!increasing && (a[i] < prev) ) ) {
increasing = !increasing;
maxLen++;
}
prev = a[i];
}
return maxLen;
}
```