Almost Uniform Sequence

Published by Mubashir Hassan in

Find the length of the longest sub-sequence of two distinct numbers whose difference is 1. A sub-sequence can be made by deleting any numbers in between.

Examples

almostUniform([1, 3, 2, 2, 5, 2, 3, 7]) ➞ 5
// [3, 2, 2, 2, 3]

almostUniform([1, 2, 3, 4]) ➞ 2
// [1, 2] or [2, 3] or [3, 4]

almostUniform([1, 1, 1, 1]) ➞ 0
// There is no sub-sequence of two distinct numbers.

Notes

N/A

Watch a quick demo on how Edabit works.