Aurora Feather Lights
You can think of this as a small game with a very specific goal. In Aurora Feather Lights, you are trying to work toward the right number by following one clear idea.
Calculate feather lantern sequence growth pattern A good way to think about it is to first understand what goes in, then what rule you must follow, and finally what shape the answer should have.
For example, if the input is sweeps = 4, the answer is 341. Four sweeps follow the rule, producing three hundred forty-one shimmering feathers. Another example is sweeps = 0, which gives 1. Only the opening feather lantern glows.
This is a friendly practice problem, but it still rewards careful reading. The key is understanding the rule clearly and then applying it carefully.
One helpful habit is to say the rule out loud in your own words before you start solving. If you can explain what counts, what changes, and what the final answer should look like, you are already much closer to the right solution.
Example Input & Output
Four sweeps follow the rule, producing three hundred forty-one shimmering feathers.
Only the opening feather lantern glows.
The second sweep adds one feather and echoes the earlier light four times.
Algorithm Flow

Best Answers
import java.util.*;
class Solution {
public int[][] find_maximal_balanced_subarrays(int[] nums) {
int p0 = 0, p1 = 0, p2 = 0;
Map<String, List<Integer>> diffs = new HashMap<>();
diffs.computeIfAbsent("0,0", k -> new ArrayList<>()).add(-1);
for (int i = 0; i < nums.length; i++) {
int r = (nums[i] % 3 + 3) % 3;
if (r == 0) p0++;
else if (r == 1) p1++;
else p2++;
String key = (p0 - p1) + "," + (p1 - p2);
diffs.computeIfAbsent(key, k -> new ArrayList<>()).add(i);
}
List<int[]> balanced = new ArrayList<>();
for (List<Integer> indices : diffs.values()) {
for (int a = 0; a < indices.size(); a++) {
for (int b = a + 1; b < indices.size(); b++) {
balanced.add(new int[]{indices.get(a) + 1, indices.get(b)});
}
}
}
List<int[]> maximal = new ArrayList<>();
for (int[] b1 : balanced) {
boolean isSub = false;
for (int[] b2 : balanced) {
if (b2[0] <= b1[0] && b2[1] >= b1[1] && (b2[0] != b1[0] || b2[1] != b1[1])) {
isSub = true;
break;
}
}
if (!isSub) maximal.add(b1);
}
maximal.sort(Comparator.comparingInt(a -> a[0]));
int[][] result = new int[maximal.size()][];
for (int i = 0; i < maximal.size(); i++) {
int start = maximal.get(i)[0];
int end = maximal.get(i)[1];
result[i] = Arrays.copyOfRange(nums, start, end + 1);
}
return result;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
