Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5704
@Quandray 5245
@akhayrutdinov 5111
@saiujwal13083 5046
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3523
@mantu_singh 3514
@sushant_a 3459
Longest sub-sequence such that difference between adjacents is one
Easy Accuracy: 54.03% Submissions: 143 Points: 2

Given an array of size n. The task is to find the longest subsequence such that absolute difference between adjacents is one.

Example 1:

Input : Arr[] = {10, 9, 4, 5, 4, 8, 6}
Output : 3
Explanation:
As longest subsequences with difference 1
are, ("10, 9, 8"), ("4, 5, 4") and
("4, 5, 6").



Example 2:

Input : Arr[] = {1, 2, 3, 2, 3, 7, 2, 1}
Output : 7



This is a function problem. The input is already taken care of by the driver code. You only need to complete the function longLenSub() that takes an array (arr), sizeOfArray (n), and return the length of the longest subsequence with absolute difference 1. The driver code takes care of the printing.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).

Constraints:
1 ≤ n, a[i] ≤ 105