← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Design a class that can incrementally compute the Ordinary Least Squares (OLS) slope coefficient for a simple linear regression model that has no intercept term. The coefficient β is defined as β = Σ(x·y) / Σ(x²). Your class must support two operations: (1) add(x, y) – incorporate a new observation (x, y); (2) get_beta() – return the current estimate of β. If the denominator Σx² is zero (i.e., every x seen so far is zero), get_beta() must return 0 to avoid division by zero. Both operations must run in O(1) time and use O(1) extra space; you are not allowed to store the individual data points.