RoofTop

public class RoofTop {

    // Returns the maximum number of consecutive increasing steps in the given array
    public static int maxSteps(int[] arr) {
        int maxStreak = 0;
        int currentStreak = 0;
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > arr[i - 1]) {
                currentStreak++;
                maxStreak = Math.max(maxStreak, currentStreak);
            } else {
                currentStreak = 0;
            }
        }
        return maxStreak;
    }

    // Example cases with values between 11 and 20
    public static void main(String[] args) {
        int[][] examples = {
            {11, 12, 12, 13, 12}, // max = 1 (11→12 or 12→13)
            {11, 12, 13, 14}, // max = 3 (11→12→13→14)
            {20, 19, 18, 17}, // max = 0 (no increasing)
            {11, 15, 13, 16, 18}, // max = 2 (16→18)
            {14, 14, 14, 14}, // max = 0
            {19}, // max = 0
            {}, // max = 0
            {11, 12, 13, 12, 13, 14, 15} // max = 3 (13→14→15)
        };

        for (int i = 0; i < examples.length; i++) {
            int result = maxSteps(examples[i]);
            System.out.println("Example " + (i + 1) + ": Output = " + result);
        }
    }
}

 

Scroll to Top