3923. Minimum Generations to Target Point
You are given a 2D integer array
pointswherepoints[i] = [x_i, y_i, z_i]represents a point in 3D space, and an integer arraytargetrepresenting a target point.Define generation 0 as the initial list of points. For each integer
k >= 1, form generationkas follows:
- Consider every pair of two distinct points
a = [x_1, y_1, z_1]andb = [x_2, y_2, z_2]taken from all points produced in generations 0 throughk - 1.- For each such pair, compute
c = [floor((x_1 + x_2) / 2), floor((y_1 + y_2) / 2), floor((z_1 + z_2) / 2)]and collect every suchcinto a generationk.- All points in the generation
kare produced simultaneously from points in generations 0 throughk - 1.- After generation
kis formed, the points in the generationkare considered available for forming later generations.Return the smallest integer
ksuch that thetargetappears in one of the generations 0 throughk. If thetargetis already in the initial points, return 0. If it is impossible to obtain thetarget, return -1.Notes:
- floor denotes rounding down to the nearest integer.
- “Two distinct points” means the two chosen points must have different
(x, y, z)coordinates. A point cannot be paired with itself, and pairing two points with identical coordinates is not possible.
1 |
|