/*
 * Recursively find the longest streak of increasing values in an array
 * 
 * @author ggtowell
 * Created: Nov 6, 2023
 */

public class LongInc {
    public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("Give me a positive integer");
            return;
        }
        int siz = Integer.parseInt(args[0]);
        if (siz < 1) {
            System.out.println("Give me a positive integer please");
            return;
        }
        double[] dd = new double[siz];
        for (int i = 0; i < dd.length; i++) {
            dd[i] = Math.random();
            System.out.println(dd[i]);
        }
        System.out.println(longIncreas(dd, 1, 1, 1));
    }

    public static int longIncreas(double[] arr, int idx, int currentStreak, int longestStreak) {
        // base case reached the end of the array
        if (idx >= arr.length) {
            return longestStreak;
        }
        if (arr[idx] > arr[idx - 1]) { 
            currentStreak++;  // streak increases
        } else {
            currentStreak = 1; // back to a streak of 1
        }
        if (currentStreak > longestStreak) {
            longestStreak = currentStreak; // the current streak is better than the longest known
        }
        return longIncreas(arr, idx + 1, currentStreak, longestStreak);
    }
}
