Problem · Array

Starlink Beam Planner

Learn this problem
HardSpaceX logoSpaceXFULLTIMENEW GRADOAPHONE SCREEN

Problem statement

You are given the positions of users and satellites as three-dimensional vectors relative to the center of a spherical Earth at (0, 0, 0). Construct a set of satellite beams that serves at least minimumServed distinct users.

Practice Contract

Implement planBeams. Return an integer matrix in which every row is [userIndex, satelliteIndex, color]:

  • userIndex and satelliteIndex are zero-based.
  • color is one of 1, 2, 3, or 4.
  • The order of the returned rows does not matter.

Your assignment must satisfy all of the following rules:

  • One beam per user: a user may appear in at most one returned row.
  • User visibility: for user vector U and satellite vector S, the angle between U and S - U must be at most 45 degrees.
  • Satellite capacity: one satellite may serve at most 32 users.
  • Frequency separation: consider two users assigned to the same satellite. If their beams use the same color, the angle between the vectors from that satellite to the two users must be at least 10 degrees.
  • Coverage: the matrix must contain at least minimumServed rows.

Any assignment satisfying these rules is accepted. It does not have to equal the reference output shown in an example, and it may serve more than minimumServed users.

Function

planBeams(users: double[][], satellites: double[][], minimumServed: int) → int[][]

Examples

Example 1

users = [[1,0,0],[0,1,0]]satellites = [[2,0,0],[0,2,0]]minimumServed = 2return = [[0,0,1],[1,1,1]]

User 0 is directly below satellite 0, and user 1 is directly below satellite 1. Both users are served, so the minimum of 2 is met.

Example 2

users = [[1,0,0],[0.996194698,0.087155743,0]]satellites = [[2,0,0]]minimumServed = 2return = [[0,0,1],[1,0,2]]

The two beams are less than 10 degrees apart at satellite 0, so the reference plan gives them different colors. Any other feasible colors are also accepted.

Example 3

users = [[1,0,0],[0,1,0]]satellites = [[2,0,0]]minimumServed = 1return = [[0,0,1]]

User 0 is visible from the satellite. Serving that user alone satisfies minimumServed = 1; user 1 may be omitted.

Constraints

  • 1 <= users.length <= 500
  • 1 <= satellites.length <= 100
  • Every user and satellite entry contains exactly three finite coordinates.
  • Every user and satellite vector is nonzero, and every coordinate has absolute value at most 10^9.
  • 0 <= minimumServed <= users.length
  • At least one valid assignment serves minimumServed users.

More SpaceX problems

drafts saved locally
public int[][] planBeams(double[][] users, double[][] satellites, int minimumServed) {
    // Write your code here.
}
users[[1,0,0],[0,1,0]]
satellites[[2,0,0],[0,2,0]]
minimumServed2
reference[[0,0,1],[1,1,1]]
checking account