Solving Longest Turbulent Subarray in go. Please try yourself first to solve the problem and submit your implementation to LeetCode before looking into solution.

Problem Description

That is, the subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray.

Example 1:

Input: [9,4,2,10,7,8,8,1,9]
Output: 5
Explanation: (A[1] > A[2] < A[3] > A[4] < A[5])

Example 2:

Input: [4,8,12,16]
Output: 2

Example 3:

Input: [100]
Output: 1

Note:

  1. 1 <= A.length <= 40000
  2. 0 <= A[i] <= 10^9
  • 1 <= A.length <= 40000
  • 0 <= A[i] <= 10^9

See the full details of the problem Longest Turbulent Subarray at LeetCode

Originally posted at: @github.com/halfrost/LeetCode-Go