For this Question: The cost of stock on each day is given in an array A[] of size N. If you can only perform at most two transactions what is the maximum profit you can gain.

Note:- The second transaction can only start after the first one is complete (Sell- >buy- >sell- >buy).The first line of input contains a single integer N. The next line of input contains N space-separated integers depicting the values of A[].

Constraints:-
2 <= N <= 10000
1 <= A[i] <= 1000000000Print the maximum profit gain in at most two transactions.Sample Input:-
5
3 5 2 8 3

Sample Output:-
8

Explanation:-
Buy at index 1, sell at index 2, Buy at index 3, sell at index 8.

Sample Input:-
4
1 2 4 5

Sample Output:-
4, I have written this Solution Code: import java.io.*;
import java.util.*;



class Main {
	public static void main (String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String str1 = br.readLine();
		String[] str2 = str1.split(" ");
		long[] arr = new long[n];
		for(int i = 0; i < n; ++i) {
			arr[i] = Long.parseLong(str2[i]);
		}












		System.out.print(maxProfit(arr, n));
	}
	static long maxProfit(long price[], int n)
    {
       long profit[] = new long[n];



        long max_price = price[n - 1];
        for (int i = n - 2; i >= 0; i--) {
            if (price[i] > max_price)
                max_price = price[i];

             profit[i] = Math.max(profit[i + 1],
                                 max_price - price[i]);
        }


        long min_price = price[0];
        for (int i = 1; i < n; i++) {
            if (price[i] < min_price)
                min_price = price[i];

            profit[i] = Math.max(
                profit[i - 1],
                profit[i] + (price[i] - min_price));
        }
        long result = profit[n - 1];
        return result;
    }
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?