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: import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;


public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in)) ;
        int n = Integer.parseInt(read.readLine()) ;
        String[] str = read.readLine().trim().split(" ") ;
        int[] arr = new int[n] ;
        for(int i=0; i<n; i++) {
            arr[i] = Integer.parseInt(str[i]) ;
        }
        int result = 0 ;
        HashMap<Integer,Integer> mp = new HashMap<>() ;
        for(int i=0; i<n; i++) {
            int len = 0 ;

            if(mp.containsKey(arr[i]-1) && mp.get(arr[i]-1) > len) {
                len = mp.get(arr[i]-1) ;
            }

            if(mp.containsKey(arr[i]+1) && mp.get(arr[i]+1) > len) {
                len = mp.get(arr[i]+1) ;
            }

            mp.put(arr[i], len+1) ;

            result = Math.max(result, mp.get(arr[i])) ;
        }

        System.out.println(result);
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?