How can i find the longest sub array with a max difference of 0 and 1 with time complexity of O(n) and space of O(1)? Thank you in advance for the feed backs & solutions!
For example: input array is {3, 3, 4, 5, 5, 5, 6, 6, 7, 7, 7, 7, 7} and output should be something like: starting index is 6 with length 7.
Another example: input array is {5, 5, 5, 5, 3, 3, 2, 2, 1} and output: index 0 and length 4.
Possible solution: I'm using nested for loops with var i and var j