Java code to find longest subarray with difference between max and min as at - most 1.
public class Demo { public static int longestSubarray ( int [ ] input ) { int prev = - 1 ; int current , next ; int prevCount = 0 , currentCount = 1 ;