Starfall Signal Map
In the Seafarer’s Cove, lookout directors chart aurora sweeps by projecting flares onto the valley floor. Each chart begins with an Origin [x, y]. A series of sky vectors then define how far mirrored flares swing from that core. Your task in Starfall Signal Map is to translate these vectors into a final list of projected coordinates for the airship captains.
The "secret sauce" here is a Recursive Wrapping Rule. For every vector [dx, dy], you update the current list: first add a new coordinate [x + dx, y + dy], then append the entire existing list, next add the mirrored point [x - dx, y - dy], and finally append the existing list again. If no vectors remain, the result is just the origin. This symmetrical expansion captures the balanced rhythm of the flares as they trace across the mountain sky! You must return the complete ordered list of integer pairs, ensuring the captains can replay the exact ceremony path with precision.
Examples
Example with input: origin = [0,0], vectors = []
Example with input: origin = [0,0], vectors = [[2,1]]
Example with input: origin = [1,-1], vectors = [[3,0], [0,2]]
Algorithm Flow

Best Answers
import java.util.*;
class Solution {
public int find_shortest_signal_path(int[][] grid) {
int rows = grid.length;
if (rows == 0) return -1;
int cols = grid[0].length;
if (grid[0][0] == 1 || grid[rows-1][cols-1] == 1) return -1;
Queue<int[]> q = new LinkedList<>();
q.add(new int[]{0, 0, 1});
boolean[][] visited = new boolean[rows][cols];
visited[0][0] = true;
int[][] dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
while (!q.isEmpty()) {
int[] curr = q.poll();
int r = curr[0], c = curr[1], d = curr[2];
if (r == rows - 1 && c == cols - 1) return d;
for (int[] dir : dirs) {
int nr = r + dir[0], nc = c + dir[1];
if (nr >= 0 && nr < rows && nc >= 0 && nc < cols && grid[nr][nc] == 0 && !visited[nr][nc]) {
visited[nr][nc] = true;
q.add(new int[]{nr, nc, d + 1});
}
}
}
return -1;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
