Correct Three Protractor Readings
Updated
Problem statement
You measure the three angles of a triangle with a protractor. The readings, in degrees, are measured[0], measured[1] and measured[2]. The true angles of a triangle always add up to exactly 180 degrees, but the readings may not.
Assume each reading equals its true angle plus a random error. The three errors are independent, each has mean 0, and all three have the same variance.
Estimate the true angles with the least-squares fix: find the three numbers t[0], t[1] and t[2] that add up to exactly 180 and make (measured[0] - t[0])^2 + (measured[1] - t[1])^2 + (measured[2] - t[2])^2 as small as possible.
Return [t[0], t[1], t[2]], in the same order as the readings. Each value is accepted if its absolute error or its relative error is at most 10^-9.
Function
correctTriangleAngles(measured: int[]) → double[]Examples
Example 1
measured = [56,55,57]return = [60.0,59.0,61.0]This is the interview case. The readings add up to 56 + 55 + 57 = 168, which is 12 degrees short of 180. The errors have the same variance, so the fix spreads the missing 12 degrees equally: each angle gets 12 / 3 = 4 more degrees. The answer is [60, 59, 61], which adds up to 180.
Example 2
measured = [60,60,60]return = [60.0,60.0,60.0]The readings already add up to 180, so nothing needs to change. The answer is [60, 60, 60].
Example 3
measured = [100,41,40]return = [99.66666666666667,40.666666666666664,39.666666666666664]The readings add up to 181, which is 1 degree too much. Each angle gives back 1 / 3 of a degree. The answer is [99 2/3, 40 2/3, 39 2/3], about [99.6667, 40.6667, 39.6667].
Constraints
measured.length == 311 <= measured[i] <= 169150 <= measured[0] + measured[1] + measured[2] <= 210
More Susquehanna International Group (SIG) interview questions
- Extract Company Tickers from NewsONSITE INTERVIEW · Seen Jul 2026
- AKQ Betting Game EquilibriumONSITE INTERVIEW · Seen May 2025
- Estimate X from the Sum of Two NormalsONSITE INTERVIEW · Seen May 2025
- Catch Fish with Reusable BaitsOA · Seen Nov 2026
- Bold Play to Reach a GoalOA · Seen Nov 2026
- Cats, Truth and Who Has MoreOA · Seen Nov 2026
- Counting Cows by Their LegsOA · Seen Nov 2026
- Enough Muffins for the LineOA · Seen Nov 2026
- Expected Consecutive Pairs Among Chosen NumbersOA · Seen Nov 2026
- Four-by-Four Boundary GridOA · Seen Nov 2026
Similar questions at other companies
- Rectangle OverlapMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Overlap Area of Two RectanglesNutanix · ONSITE INTERVIEWNutanix interview questions
- Common Part of Two RectanglesExpedia · ONSITE INTERVIEWExpedia interview questions
- Optimal Central WarehouseGoogle · ONSITE INTERVIEWGoogle interview questions
- Max Points on a LineLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Rasterize a Circle with Integer PixelsPure Storage · ONSITE INTERVIEWPure Storage interview questions
- Point Inside a TriangleSambaNova Systems · PHONE SCREEN · ONSITE INTERVIEWSambaNova Systems interview questions
- Circle Intersection in Three DimensionsNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Range of a Third CorrelationTower Research Capital · PHONE SCREEN
- Three Points in a Semicircle: Monte Carlo EstimateSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions