For this Question: Given an array of N integers, your task is to find the longest subsequence such that the difference between adjacent numbers in the subsequence is equal to 1First line of input contains a single integer N. Next line of input contains N space- separated integers depicting the elements of the array.

Constraints:-
1 <= N <= 1000
1 <= Arr[i] <= 10000Print the length of the longest subsequence.Sample Input:-
5
4 6 1 5 4

Sample Output:-
3

Explanation:-
there are two subsequences of size 3 that fit this criterion:- 4 5 4 and 6 5 4

Sample input:-
8
1 2 3 2 3 7 2 1

Sample Output:-
7, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;

// Function to find the length of longest subsequence 
int longestSubseqWithDiffOne(int arr[], int n) 
{ 
    // Initialize the dp[] array with 1 as a 
    // single element will be of 1 length 
    int dp[n]; 
    for (int i = 0; i< n; i++) 
        dp[i] = 1; 
  
    // Start traversing the given array 
    for (int i=1; i<n; i++) 
    { 
        // Compare with all the previous elements 
        for (int j=0; j<i; j++) 
        { 
            // If the element is consecutive then 
            // consider this subsequence and update 
            // dp[i] if required. 
            if ((arr[i] == arr[j]+1) || 
                (arr[i] == arr[j]-1)) 
  
                dp[i] = max(dp[i], dp[j]+1); 
        } 
    } 
  
    // Longest length will be the maximum value 
    // of dp array. 
    int result = 1; 
    for (int i = 0 ; i < n ; i++) 
        if (result < dp[i]) 
            result = dp[i]; 
    return result; 
} 
  
// Driver code 
int main() 
{ 
 int n;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++){
     cin>>a[i];
 }
 cout<< longestSubseqWithDiffOne(a,n); 
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not?