Easy to understand solution___


#1

GO solution that is easy to understand:

func solve(A []int , B int )  (int) {
    longest:=0
    if len(A) < 2 {
        return 1
    }
    for i, v := range A {
        currMin:=v
        currMax:=v
        for j:=i; j < len(A);j++ {
            if A[j] < currMin {
                currMin=A[j]
            }
            if A[j] > currMax {
                currMax=A[j]
            }
            currLong:= j-i+1
            if currMax - currMin >= B {
                break
            }
            if currLong > longest {
                longest=currLong
            }
        }
    }
    return longest
}