class JunctionBoxSorter {
    public static List<String> sortBoxes(List<String> boxList) {
        // Separate old generation (letter-based) and new generation (digit-based) boxes
        List<String> oldBoxes = new ArrayList<>();
        List<String> newBoxes = new ArrayList<>();
 
        for (String box : boxList) {
            String[] parts = box.split(" ", 2);
            if (Character.isDigit(parts[1].charAt(0))) {
                newBoxes.add(box);
            } else {
                oldBoxes.add(box);
            }
        }
 
        // Sort old boxes first by version info, then by identifier in case of ties
        Collections.sort(oldBoxes, (a, b) -> {
            String[] aParts = a.split(" ", 2);
            String[] bParts = b.split(" ", 2);
            int cmp = aParts[1].compareTo(bParts[1]);
            return cmp != 0 ? cmp : aParts[0].compareTo(bParts[0]);
        });
 
        // Combine sorted old boxes with unsorted new boxes
        List<String> result = new ArrayList<>(oldBoxes);
        result.addAll(newBoxes);
        return result;
    }
}

Ideal Days

Alexa is Amazon’s virtual Al assistant. It makes it easy to set up your Alexa enabled
devices, listen to music, get weather updates, and much more. The team is working on a
new feature that suggests days for camping based on the weather forecast.
According to a survey, a day is ideal for camping if the amount of rainfall has been non-
increasing for the prior k days from the considered day, and will be non-decreasing for
the following k days from the considered day. Given the predicted rainfall for the next n
days, find all the ideal days. Formally, the day is ideal if the following is true:

day[i-k] ≥ day[i-k+1] ≥ .... ≥ day[i-1] ≥ day[i] ≤ day[i+1] ≤ .... ≤ day[i+k-1] ≤ day[i+k]

Return the array of ideal days in ascending order. Note that the ith element of the array
represents the data for the day i + 1. It is guaranteed that the there is at least one ideal
day.

Input 1
day = (3, 2, 2, 2, 3, 4]
k = 2

Output 1
[3, 4]

Explanation
For a day to be ideal, the amount of rainfall has to be non-increasing for the prior 2 days
and non-decreasing for the following 2 days.

  • The rainfall trend for day3 is day1 ≥ day2 ≥ day3 ≤ day4 ≤ day5 so day3 is ideal.
  • The rainfall trend for day4 is day2 ≥ day3 ≥ day4 ≤ day5 ≤ day6 so day4 is ideal.

The answer is [3, 4].

Input 2
day = [1, 0, 1, 0, 1]
k = 1

Output
[2, 4]

Explanation
The following days are ideal:

  • day1 ≥ day2 ≤ day3
  • day3 ≥ day4 ≤ day5

Returns
int[]: the ideal days, sorted ascending
Constraints

  • 1 <= k <= n <= 2 • 10
  • 0 <= day[i] ≤ 10^9
    predictDays has the following parameters:
    int day[n]: predicted rainfall for each day
    k: an integer
class IdealCampingDays {
    public static List<Integer> predictDays(List<Integer> day, int k) {
        int n = day.size();
        List<Integer> result = new ArrayList<>();
        int[] left = new int[n];
        int[] right = new int[n];
 
        // Fill left array: Count consecutive non-increasing days
        for (int i = 1; i < n; i++) {
            if (day.get(i) <= day.get(i - 1)) {
                left[i] = left[i - 1] + 1;
            }
        }
 
        // Fill right array: Count consecutive non-decreasing days
        for (int i = n - 2; i >= 0; i--) {
            if (day.get(i) <= day.get(i + 1)) {
                right[i] = right[i + 1] + 1;
            }
        }
 
        // Find ideal days
        for (int i = k; i < n - k; i++) {
            if (left[i] >= k && right[i] >= k) {
                result.add(i + 1); // Convert zero-based index to one-based day
            }
        }
 
        return result;
    }
}
class Claude {
    public static List<Integer> predictDays(List<Integer> day, int k) {
        List<Integer> idealDays = new ArrayList<>();
        int n = day.size();
 
        // We need to check from k to n-k-1 as each candidate needs k days before and after
        for (int i = k; i < n - k; i++) {
            boolean isIdeal = true;
 
            // Check if this is a local minimum point
            // For k days before, verify non-increasing
            for (int j = i - k; j < i; j++) {
                if (day.get(j) < day.get(j + 1)) {
                    isIdeal = false;
                    break;
                }
            }
 
            // Continue to next candidate if not satisfied
            if (!isIdeal) continue;
 
            // For k days after, verify non-decreasing
            for (int j = i; j < i + k; j++) {
                if (day.get(j) > day.get(j + 1)) {
                    isIdeal = false;
                    break;
                }
            }
 
            // If both conditions are met, this is an ideal day
            if (isIdeal) {
                idealDays.add(i + 1); // 1-indexed result
            }
        }
 
        return idealDays;
    }
}