Best-Fit Plane Normal from 3D Points
Reported by candidates from The Voleon Group's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this The Voleon Group OA, reported September 2026, is skipping the centering step and fitting a plane through the origin instead of through the centroid. The task is plain linear algebra dressed up as a coding problem. Take 3D points, return the unit normal of the least-squares plane. There's no graph, no DP, no clever data structure. You compute a 3x3 covariance matrix and pull out its smallest eigenvector. If you blank on how to get that eigenvector without a library, StealthCoder runs invisibly during the live assessment as a safety net.
The problem
Given three-dimensional sample points, return the unit normal vector of their least-squares best-fit plane through the point centroid. The normal is the eigenvector corresponding to the smallest eigenvalue of the centered 3 x 3 covariance matrix, which is equivalent to the last right-singular vector of the centered point matrix. Choose the sign so the first component whose absolute value exceeds 1e-12 is positive. Answers within 1e-6 component-wise absolute error are accepted. Function bestFitPlaneNormal(points: double[][]) → double[] Examples Example 1 points = [[0,0,0],[1,0,0],[0,1,0],[2,3,0]] return = [0,0,1] All points lie on z = 0, whose sign-normalized unit normal is (0, 0, 1). Example 2 points = [[1,0,0],[0,1,0],[0,0,1],[0.5,0.25,0.25]] return = [0.5773502691896258,0.5773502691896258,0.5773502691896258] The samples lie on x + y + z = 1, so the unit normal has three equal positive components. Constraints 3 <= points.length <= 10^5 points[i].length == 3 Coordinates are finite and have absolute value at most 10^6. The samples are not collinear and the covariance matrix has a unique smallest eigenvalue.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that the problem reduces to a fixed 3x3 eigenproblem. Compute the centroid, subtract it from every point, and accumulate the six unique entries of the covariance matrix in one pass. That's O(n) with n up to 10^5. Then find the eigenvector of the smallest eigenvalue. Without a linear algebra library, use the closed-form trigonometric solution for symmetric 3x3 matrices, or Jacobi rotations, which are short and stable. Pitfalls: forgetting to center, with coordinates up to 10^6 causing precision loss if you use raw sums of squares, and forgetting the sign rule. Flip the vector so the first component with absolute value above 1e-12 is positive. Also normalize to unit length. Subtracting the centroid before accumulating helps numerically. If the eigen solver is where you freeze, StealthCoder is the hedge during the live OA, because it can hand you a working Jacobi routine.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Best-Fit Plane Normal from 3D Points cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass The Voleon Group's OA.
The Voleon Group reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Best-Fit Plane Normal from 3D Points FAQ
What's the actual trick in the best-fit plane normal problem?+
Center the points on the centroid, build the 3x3 covariance matrix, and return the eigenvector for the smallest eigenvalue. That direction is where the points vary least, so it's the plane normal. Everything else is numerics and the sign convention.
Do I need a library like numpy or an SVD routine?+
Don't count on one. Many OA environments limit imports, and the signature here is a plain double array. A hand-written Jacobi eigenvalue method for a symmetric 3x3 matrix is about 30 lines and accurate well within the 1e-6 tolerance.
How do I get the sign right?+
After normalizing, scan the components in order and find the first with absolute value above 1e-12. If it's negative, multiply the whole vector by -1. Skip this and you'll fail tests where the math is right but the sign is flipped.
Why does precision matter with coordinates up to 10^6?+
Squared values reach 10^12 and sums over 10^5 points get large. Subtract the centroid first so you accumulate small deviations. Compute the mean in a first pass, then accumulate covariance in a second pass, using doubles throughout.
How do I prepare for this in 48 hours?+
Write the covariance and Jacobi routine once from memory and test it on both examples. Check the flat z = 0 case and the x + y + z = 1 case. Then practice the sign normalization. The whole solution is short, so rehearsing it end to end is realistic.